在PHP中的两个远程FTP服务器之间传输文件 [英] Transfer files between two remote FTP servers in PHP
问题描述
我试图完成的是从一个FTP服务器获取文件并将其上传到另一个FTP服务器。
我正在使用此代码:
$ 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);
$ b $ if if(ftp_get($ conn_id,$ localDir,$ serverDir,FTP_BINARY)){
// ftp_fput($ conn_id,$ file,$ fp,FTP_ASCII))
}
我遇到的问题是当您使用 ftp_put
命令,它需要一个本地文件,但这个文件不在我的电脑上,所以我不能将它上传到其他ftp。
有没有一种方法可以将 ftp_get
函数刚刚获得的文件上传到另一个服务器,使用 ftp_put
?没有必要首先在你的PC上下载它?
谢谢!
ftp_get
和 ftp_put
只能用于文件,而不能用于文件夹。
使用 ftp_get
将文件从第一台服务器下载到本地临时文件夹/文件。然后使用 ftp_put
将临时文件上传到第二台服务器。
如果您想避免使用临时文件,可以使用 ftp_fget
将文件下载到内存,然后使用重新上传到第二个服务器。 ftp_fput
。
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.
What I'm trying to accomplish is to get a file from one FTP server and upload it to another FTP server.
I'm using this code:
$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))
}
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.
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?
Thanks!
Both ftp_get
and ftp_put
can operate with files only, not folders.
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.
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: How do I read a .txt file from FTP server into a variable?
- Transfer in-memory data to FTP server without using intermediate file
这篇关于在PHP中的两个远程FTP服务器之间传输文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!