Ftp_put upload empty file

I am trying to upload a file via ftp_put to a windows server.

my code is as follows:

$date = date('ymd'); $file_name = $date.'.csv'; $file_location = 'D:/inetpub/wwwroot/website.com/html/assets/'.$file_name; //set up basic connection $conn_id = ftp_connect(FTP_HOST, FTP_PORT); // login with username and password $login_result = ftp_login($conn_id, FTP_USER, FTP_PASS); // check connection if ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed!"; exit; } else { echo "Connected to FTP Server"; } $upload = ftp_put($conn_id, $file_name, $file_location, FTP_ASCII); // check upload status if (!$upload) { echo "FTP upload has failed!"; } else { echo "File Uploaded"; } // close the FTP stream ftp_close($conn_id); 

If I upload the file manually using filezilla, it works fine. If I use the code above, it creates an empty file.

+4
source share
5 answers

It turns out that UKFast blocked the connection and transmission. (They also require that this be only active mode).

Now they have unlocked it, it works great. (Before it seemed, just a timeout)

+1
source

Try transferring the file with passive mode enabled:

Passive mode

+12
source

try using FTP_BINARY instead of FTP_ASCII like this.

 $upload = ftp_put($conn_id, $file_name, $file_location, FTP_BINARY); 

PHP ftp might be a bug, but I found that it pretty much works in binary transfer mode.

+7
source

enable passive mode on

  ftp_pasv($conn_id, true); 
+1
source

Thank you "Khan Mohammed" for your reply when I added this part:

ftp_pasv ($ conn_id, true);

The file was uploaded perfectly.

0
source

Source: https://habr.com/ru/post/1316293/


All Articles