Page 1 of 1

PHP FTP_PUT Trouble

Posted: Wed Oct 27, 2010 7:15 am
by koolsamule
Hi Chaps,

I've created a web-based FTP site, but having trouble with PHP's FTP_PUT function.

I've tried:

Code: Select all

// FTP access parameters
$host = 'ftp.example.org';
$usr = 'example_user';
$pwd = 'example_password';
 
// file to move:
$local_file = './example.zip';
$ftp_path = '/data/example.zip';
 
// connect to FTP server (port 21)
$conn_id = ftp_connect($host, 21) or die ("Cannot connect to host");
 
// send access parameters
ftp_login($conn_id, $usr, $pwd) or die("Cannot login");
 
// turn on passive mode transfers (some servers need this)
// ftp_pasv ($conn_id, true);
 
// perform file upload
$upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_BINARY);
 
// check upload status:
print (!$upload) ? 'Cannot upload' : 'Upload complete';
print "\n";
 
// close the FTP stream
ftp_close($conn_id);
And also Net_FTP's FTP_PUT function:

Code: Select all

require_once 'Net/FTP.php';

  $test = new Net_FTP('www.domain.co.uk', 21);
  
  $test->connect('www.domain.co.uk', 21);
  
  $test->login('username', 'password');
  
$file_tmp = $_FILES["file"]["tmp_name"];
$file_name = $_FILES["file"]["name"];

$test->put($file_tmp, 'Uploads/'.$file_name, FTP_BINARY);
I've tested this with a very small text file and it works OK, but when I try with a zip file of around 9Mb it takes FOREVER, and sometimes doesn't upload at all, or if it does, it has a size of 0kb.

I need the script to handle big files up to 150Mb in size.

What can I do to speed up the process and is there something I have missed (current config settings > ini_set('max_upload_filesize', 150000000)) ?

Re: PHP FTP_PUT Trouble

Posted: Wed Oct 27, 2010 10:29 am
by s.dot
Maybe your PHP script is reaching it's timeout value?
Try changing that value in your php.ini file or putting this at the top of your script..

Code: Select all

set_time_limit(0)

Re: PHP FTP_PUT Trouble

Posted: Wed Oct 27, 2010 10:45 am
by koolsamule
thanks for the reply, i have done that (should have mentioned it), the script goes through the 60 second barrier, but doesn't complete.

Re: PHP FTP_PUT Trouble

Posted: Wed Oct 27, 2010 10:54 am
by icesolid
Have you made these max file size and max execution time settings in your php.ini file? Or are you doing them at execution time in your code?

Re: PHP FTP_PUT Trouble

Posted: Wed Oct 27, 2010 11:21 am
by koolsamule
execution time in the code

Re: PHP FTP_PUT Trouble

Posted: Wed Oct 27, 2010 11:24 am
by icesolid
Try doing it in your php.ini file, if you don't have the proper settings or permissions the commands you put in your code at execution time are just ignored.

Re: PHP FTP_PUT Trouble

Posted: Thu Oct 28, 2010 7:06 am
by koolsamule
Cool, I'll try that this evening (have to wait to restart IIS)