设置 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. 尝试用 Python 写了个病毒传播模拟程序

    病毒扩散仿真程序,用 python 也可以. 概述 事情是这样的,B 站 UP 主 @ele 实验室,写了一个简单的疫情传播仿真程序,告诉大家在家待着的重要性,视频相信大家都看过了,并且 UP 主也放 ...

  2. shell正则表达式提取数字

    grep 提取数字 grep -Po "\d+\.\d+"

  3. Codeforces_733_C

    http://codeforces.com/problemset/problem/733/C 从后往前一个个b对应一组组a. #include<iostream> #include< ...

  4. ELK:日志收集分析平台

    简介 ELK是一个日志收集分析的平台,它能收集海量的日志,并将其根据字段切割.一来方便供开发查看日志,定位问题:二来可以根据日志进行统计分析,通过其强大的呈现能力,挖掘数据的潜在价值,分析重要指标的趋 ...

  5. String、StringBuffer和StringBuilder总结

    String String类是不可变(final)的,对String类的任何改变,都是返回一个新的String类对象. StringBuffer 当对字符串进行修改的时候,需要使用 StringBuf ...

  6. java中list的sort()功能如何使用?如果倒序如何正序?

    list.sort()接收一个Comparable接口,其中compare方法是必须实现的,int compare(T o1, T o2);,它接受两个参数:o1,o2. o2表示list排序前的前值 ...

  7. k8s系列----索引

    day1:k8s集群准备搭建和相关介绍 day2:k8spod介绍与创建 day3:k8sService介绍及创建 day4:ingress资源和ingress-controller day5:存储卷 ...

  8. linux中的正则表达式知识梳理

    1. 正则表达式 1.1 正则表达式使用 正则表达式是开发者为了处理大量的字符串和文本而定义的一套规则和方法,使用正则表达式可以提高效率,快速获取想要的内容. 正则表达式常用于linux三剑客grep ...

  9. 珠峰-6-node

    1. js主线程是单线程的. 2. path.resolve 传('/')解析出一个绝对路径.

  10. JavaScript 箭头函数(Lambda表达式)

    Lambda表达式(箭头函数)用于表示一个函数,所以它和函数一样,也拥有参数.返回值.函数体,但它没有函数名,所以Lambda表达式相当于一个匿名函数. 使用方法: ()=>{} 小括号里放参数 ...