简体   繁体   English

使用php从ftp服务器复制文件

[英]Copy files from ftp server using php

I am trying to come up with a scehduled copy code with php. 我正在尝试用php编写加密的复制代码。
I dont have problem copying from shared folder via eg //xxx.xx.xxx/folder/filename.csv ( remote computer ). 我没有通过//。xxx.xx.xxx/folder/filename.csv(远程计算机)从共享文件夹复制的问题。 I have some files located at a ftp server. 我在ftp服务器上有一些文件。 How can I do the same? 我该怎么做?

Appreciate any help 感谢任何帮助

$file = 'ftp://xx.xx.xxx.xx/Log/123.csv';
$newfile = 'spc/ems_files/123.csv';
if ( copy($file, $newfile) ) {
    echo "Copy success!";
} else {
    echo "Copy failed.";
}

Additional info 附加信息

Bask on the feed I used php ftp function to connect to the ftp using below code based it said failed to connect. 根据我说的php ftp函数,使用下面的代码连接到ftp,它表示无法连接,因此请仔细阅读feed。 I can connect it with a FTP software like filezilla without much issue. 我可以将它与Filezilla之类的FTP软件连接,而不会出现太大问题。 What is wrong ? 怎么了 ?

$ftp_server = "10.76.170.123"; 
$ftp = ftp_connect("10.76.170.123");
if (!$ftp) die('could not connect.');

// login
$r = ftp_login($ftp, "anonymous", "");
if (!$r) die('could not login.');

// enter passive mode
$r = ftp_pasv($ftp, true);
if (!$r) die('could not enable passive mode.');

// get listing
$r = ftp_rawlist($ftp, "Log");
var_dump($r);

It looks like what you're doing should be possible, as long as the FTP server supports passive mode and you are using the correct credentials. 只要FTP服务器支持被动模式并且您使用的是正确的凭据,看起来您就可以做到。 I would double-check the path to the file, on the FTP server, is correct too. 我还要仔细检查FTP服务器上文件的路径是否正确。

http://php.net/manual/en/wrappers.php http://php.net/manual/zh/wrappers.php

http://php.net/manual/en/wrappers.ftp.php http://php.net/manual/zh/wrappers.ftp.php

Here are some other solutions you could try ... 这是您可以尝试的其他一些解决方案...

I solved the problem.default ftp connection used email address as password I used this to connect to the ftp successfully 我解决了问题。默认的ftp连接使用电子邮件地址作为密码,我使用它成功连接到ftp

$r = ftp_login($ftp, "anonymous", "anonymous@domain.com"); $ r = ftp_login($ ftp,“ anonymous”,“ anonymous@domain.com”);

So I chose to use php FTP function to do the downloading task 所以我选择使用php FTP功能来完成下载任务

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

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