设置 ftp_pasv($conn,true);  会出现下面错误   不设置 调用ftp 连接没问题  ftp_nlist  ftp_put ftp_get 等函数都不成功

ftp_nb_fput(): php_connect_nonb() failed: Operation now in progress (115)

上面问题的解决:

在ftp_pasv调用前 设置。详细介绍可以看 https://www.php.net/manual/en/function.ftp-set-option.php

ftp_set_option($conn,FTP_USEPASVADDRESS,false);

代码示例:

<?php
date_default_timezone_set('Asia/Shanghai'); // 联接FTP服务器
$conn = ftp_connect('39.108.113.37',9009);
var_dump($conn);
// 使用username和password登录
ftp_login($conn, 'lexian', 'lx2019'); ftp_set_option($conn,FTP_USEPASVADDRESS,false);
ftp_pasv($conn,true); // 获取远端系统类型
$server_os = ftp_systype($conn);
var_dump($server_os); //获取当前所在的目录
$here = ftp_pwd($conn);
var_dump($here);
// 列示文件
$filelist = ftp_nlist($conn, '.');
var_dump($filelist); //上传文件,ftp_put()函数能很好的胜任,它需要你指定一个本地文件名,上传后的文件名以及传输的类型。比方说:如果你想上传 “abc.txt”这个文件,上传后命名为“xyz.txt”,命令应该是这样:
ftp_put($conn, 'errFtp.py', 'err.py', FTP_ASCII); // 下载文件
ftp_get($conn, 'errFtp', 'errFtp.py', FTP_BINARY); //函数ftp_size(),它返回你所指定的文件的大小,使用BITES作为单位。要指出的是,如果它返回的是 “-1”的话,意味着这是一个目录
$fileSize = ftp_size($conn, 'errFtp.py');
var_dump($fileSize); $fileSize = ftp_size($conn, 'dahuaxiyou.mp4');
var_dump($fileSize); // 关闭联接
ftp_quit($conn);

下面是 tp 的ftp 代码  创建目录 采用了递归 值得看一下

<?php

namespace Think\Upload\Driver;
class Ftp {
/**
* 上传文件根目录
* @var string
*/
private $rootPath; /**
* 本地上传错误信息
* @var string
*/
private $error = ''; //上传错误信息 /**
* FTP连接
* @var resource
*/
private $link; private $config = array(
'host' => '', //服务器
'port' => 21, //端口
'timeout' => 90, //超时时间
'username' => '', //用户名
'password' => '', //密码
); /**
* 构造函数,用于设置上传根路径
* @param array $config FTP配置
*/
public function __construct($config){
/* 默认FTP配置 */
$this->config = array_merge($this->config, $config); /* 登录FTP服务器 */
if(!$this->login()){
E($this->error);
}
} /**
* 检测上传根目录
* @param string $rootpath 根目录
* @return boolean true-检测通过,false-检测失败
*/
public function checkRootPath($rootpath){
/* 设置根目录 */
$this->rootPath = ftp_pwd($this->link) . '/' . ltrim($rootpath, '/'); if(!@ftp_chdir($this->link, $this->rootPath)){
$this->error = '上传根目录不存在!';
return false;
}
return true;
} /**
* 检测上传目录
* @param string $savepath 上传目录
* @return boolean 检测结果,true-通过,false-失败
*/
public function checkSavePath($savepath){
/* 检测并创建目录 */
if (!$this->mkdir($savepath)) {
return false;
} else {
//TODO:检测目录是否可写
return true;
}
} /**
* 保存指定文件
* @param array $file 保存的文件信息
* @param boolean $replace 同名文件是否覆盖
* @return boolean 保存状态,true-成功,false-失败
*/
public function save($file, $replace=true) {
$filename = $this->rootPath . $file['savepath'] . $file['savename']; /* 不覆盖同名文件 */
// if (!$replace && is_file($filename)) {
// $this->error = '存在同名文件' . $file['savename'];
// return false;
// } /* 移动文件 */
if (!ftp_put($this->link, $filename, $file['tmp_name'], FTP_BINARY)) {
$this->error = '文件上传保存错误!';
return false;
}
return true;
} /**
* 创建目录
* @param string $savepath 要创建的目录
* @return boolean 创建状态,true-成功,false-失败
*/
public function mkdir($savepath){
$dir = $this->rootPath . $savepath;
if(ftp_chdir($this->link, $dir)){
return true;
} if(ftp_mkdir($this->link, $dir)){
return true;
} elseif($this->mkdir(dirname($savepath)) && ftp_mkdir($this->link, $dir)) {
return true;
} else {
$this->error = "目录 {$savepath} 创建失败!";
return false;
}
} /**
* 获取最后一次上传错误信息
* @return string 错误信息
*/
public function getError(){
return $this->error;
} /**
* 登录到FTP服务器
* @return boolean true-登录成功,false-登录失败
*/
private function login(){
extract($this->config);
$this->link = ftp_connect($host, $port, $timeout);
if($this->link) {
if (ftp_login($this->link, $username, $password)) {
return true;
} else {
$this->error = "无法登录到FTP服务器:username - {$username}";
}
} else {
$this->error = "无法连接到FTP服务器:{$host}";
}
return false;
} /**
* 析构方法,用于断开当前FTP连接
*/
public function __destruct() {
ftp_close($this->link);
} }

  

下面是 ftp php类  

https://www.cnblogs.com/phproom/p/9683612.html

https://blog.csdn.net/a114469/article/details/82784725

php ftp 使用 以及 php_connect_nonb() failed: Operation now in progress (115)的更多相关文章

  1. remount failed: Operation not permitted ,怎么办呢?

    remount failed: Operation not permitted ,怎么办呢? 1. 确定是否正确连接手机了$ adb devices 2. 进入shell$ adb shell 3. ...

  2. rsync: chgrp "/.hosts.NBCxBB" (in test) failed: Operation not permitted (1)

    #记一次rsync出现的错误(网上基本都是说权限问题) #这并不是权限的问题,应为实际的文件已经传过去了,但是rsync就是会报这个错误,(虽然使用是正常的,但是看着就是不爽) [root@local ...

  3. adb remount 失败:remount failed: Operation not permitted

    adb remount 失败:remount failed: Operation not permitted     关于ADB的使用,这里再说明下:经常使用命令 adb shell - 登录设备sh ...

  4. adb remount 失败remount failed: Operation not permitted

    1. 进入shell adb shell 2. shell下输入命令 shell@android:/ $ sushell@android:/ # mount -o rw,remount -t yaff ...

  5. errno的基本用法

    error是一个包含在 perror()和strerrot()函数可以把errno的值转化为有意义的字符输出. #include <stdio.h> #include <stdlib ...

  6. linux关于 文件/文件夹的操作 中

    说一个关于stat函数 stat函数 表头文件:    #include <sys/stat.h> 函数定义:    int stat(const char *file_name, str ...

  7. Operating System Error Codes

    How To Fix Windows Errors Click here follow the steps to fix Windows and related errors. Instruction ...

  8. 【RL-TCPnet网络教程】第37章 RL-TCPnet之FTP客户端

    第37章      RL-TCPnet之FTP客户端 本章节为大家讲解RL-TCPnet的FTP客户端应用,学习本章节前,务必要优先学习第35章的FTP基础知识.有了这些基础知识之后,再搞本章节会有事 ...

  9. Linux建立FTP服务器

    http://blog.chinaunix.net/uid-20541719-id-1931116.html http://www.cnblogs.com/hnrainll/archive/2011/ ...

随机推荐

  1. Newcoder Wannafly13 B Jxy军训(费马小定理、分数在模意义下的值)

    链接:https://www.nowcoder.com/acm/contest/80/B 题目描述 在文某路学车中学高一新生军训中,Jxc正站在太阳下站着军姿,对于这样的酷热的阳光,Jxc 表示非常不 ...

  2. requests的post提交form-data; boundary=????

    提交这种用boundary分隔的表单数据时,有两种方法,一种是以传入files参数,另一种是传入data参数,data参数需要自己用boundary来分隔为指定的形式,而files参数则以元组的形式传 ...

  3. 大数据篇:HDFS

    HDFS HDFS是什么? Hadoop分布式文件系统(HDFS)是指被设计成适合运行在通用硬件(commodity hardware)上的分布式文件系统(Distributed File Syste ...

  4. php gettype()函数

      gettype() 会根据 参数类型返回值: boolean:表示变量为布尔类型 integer:表示变量为整数类型 double :表示变量为float类型(历史原因) string:表示变量为 ...

  5. 通过 Serverless 加速 Blazor WebAssembly

    Blazor ❤ Serverless 我正在开发 Ant Design 的 Blazor 版本,预览页面部署在 Github Pages 上,但是加载速度很不理想,往往需要 1 分钟多钟才完成. 项 ...

  6. 搭建ELK 集群 rpm安装

    上次是使用docker搭建的ELK,三个软件都跑在一台机器的一个docker中,这个就当是测试环境吧. 下面开始搭建正式环境下的ELK集群. 三台服务器 A:logstash B:Elasticsea ...

  7. [Redis-Python]发布订阅通过Redis异步发送邮件

    接收订阅 #!/usr/bin/env pyhton # coding:utf-8 # @Time : 2020-02-16 21:36 # @Author : LeoShi # @Site : # ...

  8. 【全集】IDEA入门到实战

    课程介绍   IDEA是一款功能强悍.非常好用的Java开发工具,近几年编程开发人员对IDEA情有独钟.虽然IDEA功能很强大,但目前市面讲解的不细致.不系统,导致很多IDEA初学者要么无从下手,要么 ...

  9. B树(B-树) 、B+树

    B树(B-树) 1.B-树(B树)的基本概念B-树中所有结点中孩子结点个数的最大值成为B-树的阶,通常用m表示,从查找效率考虑,一般要求m>=3.一棵m阶B-树或者是一棵空树,或者是满足以下条件 ...

  10. Python学习小记(3)---scope&namespace

    首先,函数里面是可以访问外部变量的 #scope.py def scope_test(): spam = 'scope_test spam' def inner_scope_test(): spam ...