Transfer files between two remote FTP servers in P

2020-03-26 17:26发布

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!

标签: php ftp
1条回答
来,给爷笑一个
2楼-- · 2020-03-26 18:21

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.

查看更多
登录 后发表回答