Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ftp upload not working

Tags:

php

File is not uploading to FTP and errors: Warning: ftp_put() [function.ftp-put]: Can't open that file: No such file or directory coming. We are using following code:

    $server = 'ftp.domain.com';
$ftp_user_name = '[email protected]';
$ftp_user_pass = 'password';
$dest = 'files/test.txt';
$source = 'test.txt';
$src = ini_get("upload_tmp_dir");

$connection = ftp_connect($server);
$login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);
if (!$connection || !$login) { die('Connection attempt failed!'); }
$upload = ftp_put($connection, $dest, $source, FTP_BINARY);
if (!$upload) { echo 'FTP upload failed!'; }
ftp_close($connection); 
like image 695
seoppc Avatar asked Mar 24 '11 21:03

seoppc


People also ask

Why my FTP is not working?

Your firewall could be blocking it. Ensure you have the IP address in your welcome email for hostname (only the numbers; don't add FTP, www, or anything else). Make sure your username and password are the same as your control panel username and password. Some FTP programs require a path to connect.

Is there a file size limit for FTP?

Answer: There is not a limit on the size of the file. But keep in mind that the bigger the file the longer it will take to be transferred. However, either a ReadTimeout or OutOfMemory message may appear, depending on how many files are on the ftp server, and how large the files are.

Why is my FTP upload so slow?

FTP upload and download speed depend mainly on the client's connection to the server. This may be affected by multiple network factors such as hop count and local connectivity. Also, there are other factors which may affect the speed: The number of clients that currently are using the FTP service.


2 Answers

Here's an answer from the comments of php.net on ftp_put:


Found the prob, you can't put a path to the destination file (even though I can do that in the dos ftp client...?)

e.g. - this doesn't work

ftp_put($conn, '/www/site/file.html','c:/wamp/www/site/file.html',FTP_BINARY);

you have to put

ftp_chdir($conn, '/www/site/');
ftp_put($conn,'file.html', 'c:/wamp/www/site/file.html', FTP_BINARY );

http://php.net/manual/en/function.ftp-put.php

like image 169
Ryre Avatar answered Oct 23 '22 02:10

Ryre


I had same problem and I solved it using ftp_nb_put(). Same function but it allows your program to run more connections or something:-)

like image 36
user3002411 Avatar answered Oct 23 '22 03:10

user3002411