Warning: ftp_get() [function.ftp-get]: Error opening
Posted: Fri Oct 24, 2008 9:14 am
Why won't some files overwrite?
I'm copying images from an FTP server to a local directory. Some of the images copy successfully, but others do not. If the file doesn't exist locally it works fine. If the file already exists and the ftp_get should overwrite, then sometimes it fails and sometimes it works. All the files have the same permissions (rw-rw-rw). The only difference that I can see between files that work or not is the date stamp...files that fail have a timestamp older than the ftp version. E.g. ftp version (10/23/2008), local version (10/21/2008). Files transfers that work are the reverse. This is the error I get:
Warning: ftp_get() [function.ftp-get]: Error opening /home/ici/webdocs/pub/htdocs/public/apimages/LFANN54633.JPG in /home/ici/webdocs/pub/htdocs/scripts/ftptest2.php on line 12
Transer failed
I have a larger script that gets the file list from the FTP server and loops through each file, but for testing I just created this small test script that recreates the same results.
I suppose one solution would be to delete the local file if it exists before the ftp_get, but I thought this function would overwrite the file?
Your help is appreciated?
I'm copying images from an FTP server to a local directory. Some of the images copy successfully, but others do not. If the file doesn't exist locally it works fine. If the file already exists and the ftp_get should overwrite, then sometimes it fails and sometimes it works. All the files have the same permissions (rw-rw-rw). The only difference that I can see between files that work or not is the date stamp...files that fail have a timestamp older than the ftp version. E.g. ftp version (10/23/2008), local version (10/21/2008). Files transfers that work are the reverse. This is the error I get:
Warning: ftp_get() [function.ftp-get]: Error opening /home/ici/webdocs/pub/htdocs/public/apimages/LFANN54633.JPG in /home/ici/webdocs/pub/htdocs/scripts/ftptest2.php on line 12
Transer failed
I have a larger script that gets the file list from the FTP server and loops through each file, but for testing I just created this small test script that recreates the same results.
Code: Select all
$ftp_server = 'ftp.server;
$ftp_user = 'username';
$ftp_password = 'password';
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user, $ftp_password);
ftp_pasv($conn_id, true);
$ret = ftp_get($conn_id, "/home/ici/webdocs/pub/htdocs/public/apimages/LFANN54633.JPG", "photos/LFANN54633.JPG", FTP_BINARY);
if ($ret)
{
echo "Transfer successful<br>";
}
else
{
echo "Transer failed <br>";
}
ftp_close($conn_id);
Your help is appreciated?