简体   繁体   中英

Transfer files between two remote FTP servers in PHP

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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