Why does the download via ftp interrupts?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lgman
Forum Newbie
Posts: 2
Joined: Wed Apr 16, 2008 3:03 am

Why does the download via ftp interrupts?

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Why does the download via ftp interrupts?

Post 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.
lgman
Forum Newbie
Posts: 2
Joined: Wed Apr 16, 2008 3:03 am

Re: Why does the download via ftp interrupts?

Post by lgman »

I'm so sorry about that! Didn't notice.

So...any idea? :mrgreen:


lgman
Post Reply