简体   繁体   English

将文件发送到 ftp 服务器

[英]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"警告:ftp_put():无法打开传输“/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.我可以通过 ftp 应用程序访问 ftp,我可以通过该应用程序创建和传输文件,但是当我尝试通过 PHP 执行相同操作时,它不起作用。

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.我在这里遗漏了什么吗,我无权更改 ftp 服务器上的任何内容,但我知道我们之前已将文件远程放置在服务器中。

Here is also a screenshot of the Ftp-connection I am using in WinSCP.这也是我在 WinSCP 中使用的 Ftp 连接的屏幕截图。 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.我还尝试在服务器上创建一个文件并执行了 ftp_get 但得到了相同的结果。

在此处输入图像描述

I checked your code, and server.txt file will be root of path.我检查了您的代码, server.txt文件将成为路径的root

In general, ftp user do not have write permission on root.一般情况下, ftp用户没有root的write权限。

Please create new directory with 777 permission and try to upload.请创建具有 777 权限的新目录并尝试上传。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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