问题描述
首先,我知道这是一个重复的主题,但是我发现的另一个帖子对我的情况没有用,所以我决定创建一个新的.
First of all, I know that this a duplicate topic, but the other post that I found were not useful for my situation, so I decided to create a new one.
我想要完成的是从一台 FTP 服务器获取文件并将其上传到另一台 FTP 服务器.
What I'm trying to accomplish is to get a file from one FTP server and upload it to another FTP server.
我正在使用此代码:
$ftp_server = "ftp_server";
$ftp_user_name = 'ftp_username' ;
$ftp_user_pass = 'ftp_pass' ;
$localDir = "full/path/";
$serverDir = "full/path/";
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if (ftp_get($conn_id, $localDir, $serverDir, FTP_BINARY)) {
// ftp_fput($conn_id, $file, $fp, FTP_ASCII))
}
我遇到的问题是当你使用 ftp_put
命令时,它需要一个本地文件,但是这个文件不在我的电脑上,所以我无法将它上传到另一个 ftp.
The problem that I have is when you use ftp_put
command, it requires a local file, but this file it's not on my computer, so I can't upload it to the other ftp.
有没有办法使用 ftp_put
将我刚刚通过 ftp_get
函数获得的文件上传到另一台服务器?无需先在 PC 上下载?
Is there a way to upload the file that I just got with ftp_get
function into another server using ftp_put
? Without the need to download it first on your PC?
谢谢!
推荐答案
ftp_get
和 ftp_put
都只能操作文件,不能操作文件夹.
Both ftp_get
and ftp_put
can operate with files only, not folders.
使用 ftp_get
将文件从第一台服务器下载到本地临时文件夹/文件.然后使用ftp_put
将临时文件上传到第二台服务器.
Use ftp_get
to download a file from the first server to a local temporary folder/file. And then use ftp_put
to upload the temporary file to the second server.
如果您想避免使用临时文件,可以使用 ftp_fget
将文件下载到内存,然后使用 ftp_fput
重新上传到第二个服务器.
If you want to avoid using a temporary file, you can download the file to memory using ftp_fget
and re-upload to the second server using ftp_fput
.
- PHP:如何将 .txt 文件从 FTP 服务器读取到变量中?
- 在不使用中间文件的情况下将内存数据传输到 FTP 服务器
这篇关于在 PHP 中的两个远程 FTP 服务器之间传输文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!