lgman Posted April 16, 2008 Share Posted April 16, 2008 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) <?php $remote_file = ""; $local_file = ""; $conn_id = ftp_connect($SVAR['remoteserver']); // might be 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 Link to comment https://forums.phpfreaks.com/topic/101322-why-does-the-download-via-ftp-interrupts/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.