简体   繁体   English

是否可以使用PHP将文件从FTP上传到FTP

[英]Is it possible to upload files from FTP to FTP using PHP

Here is my prob in Brief. 这是我的简要问题。

I know how to upload a file to server using FTP with programming language PHP. 我知道如何使用FTP编程语言PHP将文件上传到服务器。

But is that possible to get files from another server to our server using PHP with 但是可以使用PHP将文件从另一台服务器传送到我们的服务器

having the FTP Username and Password 拥有FTP用户名和密码

Thanks n advance... 谢谢你提前...

Fero FERO

Yes, you can fetch files from FTP using PHP - using ftp_get . 是的,您可以使用PHP从FTP获取文件 - 使用ftp_get

The following snippet is from the documentation : 以下代码段来自文档

$conn_id = ftp_connect($ftp_server);

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

// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successfully written to $local_file\n";
}
else {
    echo "There was a problem\n";
}

Technically, the FTP protocol allows for server-to-server transfers, called FXP . 从技术上讲,FTP协议允许服务器到服务器的传输,称为FXP This feature is disabled by default on most FTP servers, though, for security reasons, so you would need to be able to verify/enable it before it would work. 但是,出于安全原因,默认情况下在大多数FTP服务器上禁用此功能,因此您需要能够在它工作之前验证/启用它。

If it is enabled, you should just need to script the FXP commands and everything should work fine. 如果它已启用,您只需要编写FXP命令的脚本,一切都应该正常工作。

Here's a link to a promising function: 这是一个有前途的功能的链接:

http://www.php.net/manual/en/function.ftp-fget.php http://www.php.net/manual/en/function.ftp-fget.php

You'll need to open the local file up for dumping into, and manage the connection and whatnot, but this is the way to do it. 您需要打开本地文件以进行转储,并管理连接等等,但这是实现此目的的方法。

我不认为这与将文件从目录复制到另一个目录有很大不同,前提是您知道如何在FTP服务器中打开文件。

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

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