【发布时间】:2015-12-04 10:52:41
【问题描述】:
我正在尝试将文件从 FTP 远程服务器复制到另一台 FTP 远程服务器,但收到警告:
Warning: copy(): The first argument to copy() function cannot be a directory in
我已经仔细检查了我的文件夹名称和文件路径,一切都是正确的。我可以在嵌套的foreach() 之外成功使用copy(),但是一旦我添加嵌套循环并放入copy(),它就会窒息。
这是我的代码:
// set-up basic connection
$one_connection = ftp_connect("ftp.***.com");
$two_connection = ftp_connect("ftp.***.com");
// login with username and password
$one_login_result = ftp_login($one_connection, $one_user, $one_pass);
$two_login_result = ftp_login($two_connection, $two_user, $two_pass);
// get a list of directories on ftp server
$directories = ftp_nlist($one_connection, "ftp_images/rsr_number/");
// log start time
$start_time = date('Hi');
// loop through and pull all images from each directory
foreach($directories as $dir)
{
// get list of images in directory
$images = ftp_nlist($one_connection, "ftp_images/img_number/".$dir);
foreach($images as $img)
{
copy('ftp://user:pass@ftp.****.com/ftp_images/img_number/' .$dir . '/' . $img, 'ftp://user:pass@ftp.***.com/public_html/temp/' . $img);
}
}
ftp_close($one_connection);
ftp_close($two_connection);
为什么我会收到此警告?
另外,这是连接两个远程 FTP 服务器的正确方法吗?
编辑
这是var_dump() 的$directories:
array(27) {
[0]=>
string(1) "#"
[1]=>
string(1) "a"
[2]=>
string(1) "b"
[3]=>
string(1) "c"
[4]=>
string(1) "d"
[5]=>
string(1) "e"
[6]=>
string(1) "f"
[7]=>
string(1) "g"
[8]=>
string(1) "h"
[9]=>
string(1) "i"
[10]=>
string(1) "j"
[11]=>
string(1) "k"
[12]=>
string(1) "l"
[13]=>
string(1) "m"
[14]=>
string(1) "n"
[15]=>
string(3) "num"
[16]=>
string(1) "o"
[17]=>
string(1) "p"
[18]=>
string(1) "r"
[19]=>
string(1) "s"
[20]=>
string(1) "t"
[21]=>
string(1) "u"
[22]=>
string(1) "v"
[23]=>
string(1) "w"
[24]=>
string(1) "x"
[25]=>
string(1) "y"
[26]=>
string(1) "z"
}
【问题讨论】:
-
$dir 和 $img 有值吗?
-
是的,
$img给出了图像名称,$dir给出了目录名称。我已经验证它是正确的。