简体   繁体   中英

Send file to ftp-server

I need to transfer an file created but I keep getting the following error:

Warning: ftp_put(): Can't open data connection for transfer of "/server.txt"

I can access the ftp via an ftp application and I can create and transfer files via the application but when I try to do the same via PHP it doesn't work.

This is my code.

$serverFile = "server.txt";
$localfile = "/var/sites/store/publish/store-201908-1323-rev9286/www/text.txt";
$localfile = "text.txt";

//Connect to ftp
$ftp_server = "111.111.111.11";
$ftp_user_name = "username";
$ftp_user_pass = "password";

/*set up basic ssl connection*/
$ftp = ftp_ssl_connect($ftp_server);

// login with username and password
$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);
ftp_pasv($ftp, true);

if($login_result){
    if (ftp_put($ftp, $serverFile, $localfile, FTP_ASCII))
    {
        Mage::log("successfully uploaded \n",null,"ftp.log");
    }
}

ftp_close($ftp);   

 

Am I missing something here, I do not have access to change anything on the ftp-server but I am aware that we have remotely placed files in the server previously.

Here is also a screenshot of the Ftp-connection I am using in WinSCP. I've tried adding the port. I also tried creating a file on the server and did a ftp_get but got the same result.

在此处输入图像描述

I checked your code, and server.txt file will be root of path.

In general, ftp user do not have write permission on root.

Please create new directory with 777 permission and try to upload.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM