I'm trying to copy files from an FTP remote server to another FTP remote server and I'm getting a warning:
Warning: copy(): The first argument to copy() function cannot be a directory in
I've double checked my folder names and file path and all is correct. I can successfully use copy()
outside the nested foreach()
, but as soon as I add the nested loop and put the copy()
it chokes.
Here's my code:
// 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);
Why am I getting this warning?
Also, is this the proper way to connect two remote FTP servers?
EDIT
Here's a var_dump()
for $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"
}