我想寫一個腳本,將從FTP服務器下載文件。它們都相當大(每個接近2GB)。該腳本開始運行,但最終終止於上述錯誤。它與尺寸有關嗎?有沒有解決的辦法?代碼如下:php - ftp_get - 警告:ftp_get():打開BINARY模式數據連接
<?php
$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<BR>\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);
}
?>
似乎是一個奇怪的警告,和我預料的錯誤信息。 – 2011-05-20 15:34:54
@Tomalak我在你身邊。 – 2011-05-23 14:43:37
這也是我的問題。謝謝! – 2015-01-10 00:23:13