Jump to content

Recommended Posts

Hey guys,

Im writing a script that connects to one ftp server downloads files to my computer, uploads them to a second and then deletes them from my comp.

I tried running it last night and all went bad.

From what i can tell most errors have been fixed except one. My php error log is showing hundreds and hundreds of the following:

 

[12-May-2007 02:28:47] PHP Warning: ftp_get(): 7858.4 kbytes to download in C:\apache2triad\htdocs\ftp\swf\main.php on line 38

 

Is that a limit thats set somewhere that it cant download a file that size? There are LOADS of that error.

The script downloaded about 100 of the files but there are over 1000, and the rest didnt get downloaded cause of this error.

Anyone know whats causing it?

 

Thank you so much,

Andy

Link to comment
https://forums.phpfreaks.com/topic/51060-ftp-script-limits/
Share on other sites

No guarantee this will work but after trawling through php.ini it looks like these four options may allow you to tweak them to allow your script to deal with larger files!

 

<?php

ini_set("post_max_size", "value"); // Default 8M
ini_set("max_execution_time", "value"); // Default 30 (seconds)
ini_set("memory_limit", "value"); // Default 8M
ini_set("upload_max_filesize", "value"); // Default 2M

/* Your code here */

?>

 

Not 100% sure if that will work, but it's worth a go :)

Link to comment
https://forums.phpfreaks.com/topic/51060-ftp-script-limits/#findComment-251278
Share on other sites

Yeah thats chigley, the problem in php.ini the resource limits..

max_execution_time = 30

; Maximum execution time of each script, in seconds

max_input_time = 300

; Maximum amount of time each script may spend parsing request data

memory_limit = 80000M

; Maximum amount of memory a script may consume (8MB)

It was set to only 8M so i put a few 0's after it :P only for the moment

Here is the script..

It gave me a bit of a scare there, with the new ini settings the script ran, but it ran twice, downloading the files to 2 different folders. and when i killed the script, it didnt stop downloading to one of the folders, so i killed apache.. and that didnt even stop it.

But lucky enough apache crashed and it stopped :P

 

Here is the code.

<?php

function slog($string){
$fp = fopen('log.txt', 'a');
fputs($fp, $string . '
');
fclose($fp);
}
slog('STARTING PROCESS AT: ' . gmdate("l dS \of F Y h:i:s A"));
set_time_limit(300000);
$game_host = '';
$game_user = '';
$game_pass = '';
$game_dir = '/public_html/old/swf/';
$game_conn = ftp_connect($game_host);

$flash_host = '';
$flash_user = '';
$flash_pass = '';
$flash_dir = '/public_html/swf/';
$flash_conn = ftp_connect($flash_host);

$my_dir = '/apache2triad/htdocs/ftp/swf';

if (!$game_conn){
die('Could not connect to server: ' . $game_host);
}

if (!ftp_login($game_conn, $game_user, $game_pass)){
ftp_quit($conn);
exit('Failed to login to GAME with supplied details.');
}

ftp_chdir($game_conn, $game_dir);
$swf_files = ftp_nlist($game_conn, $game_dir);
opendir($my_dir);
for($i=0;$i<count($swf_files);$i++) {
       if(!ftp_get($game_conn,$swf_files[$i],$swf_files[$i],FTP_BINARY)) {
           echo 'Could not download ' . $files[$i];
        } else {
	echo 'Got a file!
	';
	}
    }
echo 'All Files Downloaded
';
slog('All Files Downloaded: ' . gmdate("l dS \of F Y h:i:s A"));

ftp_quit($game_conn);

$dp = opendir($my_dir);

while ($currentFile !== false){
$currentFile = readdir();
$theFiles[] = $currentFile;
}

$swfFiles = preg_grep("/swf$", $theFiles);

foreach ($swfFiles as $currentFile){
ftp_put($flash_conn, $currentFile, $currentFile, FTP_BINARY);
echo 'Uploaded ' . $currentFile . '
';
}
echo 'All Files Uploaded
';
slog("All Files Uploaded: " . gmdate("l dS \of F Y h:i:s A"));
ftp_quit($flash_conn);
echo 'Deleting Files Now';

foreach ($swfFiles as $currentFile){
unlink($currentFile);
echo 'Deleted: ' . $currentFiles;
}
slog('Ending process at: ' . gmdate("l dS \of F Y h:i:s A"));
?>

 

I think that would have fixed it, anything else wrong?

Link to comment
https://forums.phpfreaks.com/topic/51060-ftp-script-limits/#findComment-251284
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.