php ftp get 错误,php – ftp_get – 警告:ftp_get():打开BINARY模式数据连接

我正在尝试编写一个从FTP服务器下载文件的脚本.它们都相当大(每个近2GB).该脚本开始运行,但最终会因上述错误而终止.尺寸有关吗?有没有解决的办法?这是代码:

$ftp_server = "ftp.EXAMPLE.com";

$conn_id = ftp_connect ($ftp_server) or die("Couldn't connect to $ftp_server");

$login_result = ftp_login($conn_id, "USERNAME", "PASSWORD");

if ((!$conn_id) || (!$login_result)) die("FTP Connection Failed");

ftp_sync("download");

ftp_close($conn_id);

$mkdir = date('Y-m-d');

mkdir('encrypted/'.$mkdir, 0777);

smartCopy("./download/", 'encrypted/'.$mkdir);

chmodr("encrypted/".$mkdir, 0777);

function ftp_sync ($dir) {

global $conn_id;

if ($dir != ".") {

if (ftp_chdir($conn_id, $dir) == false) {

echo ("Change Dir Failed: $dir
\r\n");

return;

}

if (!(is_dir($dir)))

mkdir($dir);

chdir ($dir);

}

$contents = ftp_nlist($conn_id, ".");

foreach ($contents as $file) {

if ($file == '.' || $file == '..')

continue;

if (@ftp_chdir($conn_id, $file)) {

ftp_chdir ($conn_id, "..");

ftp_sync ($file);

}

else

ftp_get($conn_id, $file, $file, FTP_BINARY);

}

ftp_chdir ($conn_id, "..");

chdir ("..");

}

function chmodr($path, $filemode) {

if (!is_dir($path))

return chmod($path, $filemode);

$dh = opendir($path);

while (($file = readdir($dh)) !== false) {

if($file != '.' && $file != '..') {

$fullpath = $path.'/'.$file;

if(is_link($fullpath))

return FALSE;

elseif(!is_dir($fullpath) && !chmod($fullpath, $filemode))

return FALSE;

elseif(!chmodr($fullpath, $filemode))

return FALSE;

}

}

closedir($dh);

if(chmod($path, $filemode))

return TRUE;

else

return FALSE;

}

function smartCopy($source, $dest, $folderPermission='0777',$filePermission='0777'){

$result=false;

if (is_file($source)) {

if(is_dir($dest)) {

if ($dest[strlen($dest)-1]!='/')

$__dest=$dest."/";

$__dest .= basename($source);

}

else {

$__dest=$dest;

}

$result=copy($source, $__dest);

chmod($__dest,$filePermission);

}

elseif(is_dir($source)) {

if(!is_dir($dest)) {

@mkdir($dest,$folderPermission);

chmod($dest,$folderPermission);

}

if ($source[strlen($source)-1]!='/')

$source=$source."/";

if ($dest[strlen($dest)-1]!='/')

$dest=$dest."/";

$return = true;

$dirHandle=opendir($source);

while($file=readdir($dirHandle)) {

if($file!="." && $file!="..") {

$result=smartCopy($source.$file, $dest.$file, $folderPermission, $filePermission);

}

}

closedir($dirHandle);

}

else {

$result=false;

}

return $result;

}

function deleteDirectory($dir) {

if (!file_exists($dir)) return true;

if (!is_dir($dir) || is_link($dir)) return unlink($dir);

foreach (scandir($dir) as $item) {

if ($item == '.' || $item == '..') continue;

if (!deleteDirectory($dir . "/" . $item)) {

chmod($dir . "/" . $item, 0777);

if (!deleteDirectory($dir . "/" . $item)) return false;

};

}

return rmdir($dir);

}

?>

解决方法:

你确定每个文件都是二进制文件吗?

标签:php,binary,ftp

来源: https://codeday.me/bug/20191008/1870979.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值