Page 1 of 1

Why does the download via ftp interrupts?

Posted: Wed Apr 16, 2008 3:24 am
by lgman
Hi all,

I'm using a script for downloading files from a specific folder (online) to the local pc/laptop. 2nd is that while downloading I'm checking the file local with if(!file_exists) to avoid overwriting. the issue is that the download is always incomplete.

(using php 5.x on a local pc that connects to the internet via ftp)

Code: Select all

<?php
$remote_file = "";
$local_file = "";
 
    
    
$conn_id = ftp_connect($SVAR['remoteserver']); // might be http://www.mydomainname.com
 
// I thouhgt that the timeout would be the reason for the incomplete download but it's not.
# ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 1800);
 
// Login
$login_result = ftp_login($conn_id, $SVAR['serverftpuser'], $SVAR['serverftppass']); // myusername, myuserpass
 
 
 
if ((!$conn_id))
{ 
    echo "could not connect to server.";
    exit; 
}
 
ftp_pasv($conn_id, true);
 
ftp_chdir($conn_id, $SVAR['rem_imgtn']); // remote image directory
 
 
// content of the current directory
$contents = ftp_nlist($conn_id, ".");
if(count($contents) == 0)
{
    echo "directory on ftp server is empty.";
}
else
{
    foreach($contents as $filename) // SVAR['loc_imgtn'] <- local file path
    {
        if(!file_exists($SVAR['loc_imgtn'] ."/" .$filename)) // don't download the file if we've got it already!
        {
            $remote_file = $filename;
            $local_file = $SVAR['loc_imgtn'] ."/" .$filename;
        
            // well, it didn't work with the 'handle' and 'ftp_fget'(...)
            #$handle = fopen($local_file, 'w');
        
            ftp_get($conn_id, $local_file, $remote_file, FTP_BINARY);
        }
    }
    
}
    
#fclose($handle);
 
// close FTP 
ftp_close($conn_id); 
?>
So, sometimes it downloads 10 of 17 files, and sometimes 12 of 17 files... I looked for other solutions providing download from ftp and comparing files and actually I thought that the snippet I've written can handle that job.

EDIT: Could it be that the file name is too long? what's the max. char for naming a file? is "020408158077uzhzee_22832ca87u88_gtfrggtz_hhgt_9i8u765_RX20897z.jpg" too long? I don't think because ftp-tools can download those easily.

Thank you so much for any idea or suggestions.

lgman

Re: Why does the download via ftp interrupts?

Posted: Wed Apr 16, 2008 5:17 am
by Chris Corbyn
There is no need to make your text huge? Setting the font size to 150 just put me off reading your thread entirely. Please don't do that again.

Re: Why does the download via ftp interrupts?

Posted: Wed Apr 16, 2008 5:27 am
by lgman
I'm so sorry about that! Didn't notice.

So...any idea? :mrgreen:


lgman