My script packs some files with ZIP then uploads this ZIP to another server. After the upload it checks size of the ZIP on the FTP and locally. If sizes are the same- the local ZIP is deleted.
The problem is ftp_size()
returns -1. But only in the real script. In my test script it works fine.
Test script works like this:
$f = ftp_connect(HOST);
$res = ftp_login($f, USER, PASS);
$fname = 'archive_2018-09-18_13-39';
$fsize = ftp_size($f, "$fname-img.zip").'';
$fsize2 = filesize("backup/$fname-img.zip").'';
echo $fsize . '<br>' . $fsize2;
and it returns:
22907946995
22907946995
The real script works like this:
$f = ftp_connect(HOST);
$res = ftp_login($f, USER, PASS);
$fname = 'archive_' . date('Y-m-d_H-i');
exec("zip -r -0 backup/$fname-img.zip \"website\" 2>&1");
exec('curl -T "' . "backup/$fname-img.zip" . '" ftp://' . HOST . ' --user ' . USER . ':' . PASS . ' 2>&1');
$fsize = ftp_size($f, "$fname-img.zip").'';
$fsize2 = filesize("backup/$fname-img.zip").'';
echo $fsize . '<br>' . $fsize2;
and it shows:
-1
22907946995
Real script uploads file just fine. It just doesn't show correct size on the FTP server. So it's not a problem with size of the file and not a problem with FTP connection.
ftp_put()
to upload the file? Oh, and -1 probably just means the file, in the checked directory, doesn't exist.-1
, try and call error_get_last() and log it to check if that gives you any clues.