PHP FTP_PUT Trouble

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
koolsamule
Forum Contributor
Posts: 130
Joined: Fri Sep 25, 2009 10:03 am

PHP FTP_PUT Trouble

Post 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)) ?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: PHP FTP_PUT Trouble

Post 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)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
koolsamule
Forum Contributor
Posts: 130
Joined: Fri Sep 25, 2009 10:03 am

Re: PHP FTP_PUT Trouble

Post 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.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Re: PHP FTP_PUT Trouble

Post 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?
koolsamule
Forum Contributor
Posts: 130
Joined: Fri Sep 25, 2009 10:03 am

Re: PHP FTP_PUT Trouble

Post by koolsamule »

execution time in the code
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Re: PHP FTP_PUT Trouble

Post 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.
koolsamule
Forum Contributor
Posts: 130
Joined: Fri Sep 25, 2009 10:03 am

Re: PHP FTP_PUT Trouble

Post by koolsamule »

Cool, I'll try that this evening (have to wait to restart IIS)
Post Reply