Well, I'm trying to transfer files(+ directories) using PHP FTP functions from one server (source) to another (destination) & executing the script from third system. Is it possible? Can anyone help by providing an example?
Asked
Active
Viewed 1,128 times
-1
-
It's possible if you use your third system as a staging post. Unless you have access to run scripts on at least one of the two servers I can't see how you could transfer directly with FTP – Jul 22 '13 at 08:24
-
Probably you can download it to the third system from source and upload it to the destination system after that? (will only be useful with small files of course). You can also try to run a transfer script on the source or destination system from the third system (like @MikeW is suggesting). – Pieter Jul 22 '13 at 08:27
-
Thx 4 reply. I've FTP access to both source & destination servers. Also I tried running script on local computer & source server n It worked by transfering files/directories from those servers but I'm trying like while executing the script on third system which performs the execution of transfering files from source server to destination..Is this weird or smething? – Jenson M John Jul 22 '13 at 09:00
-
Yes this is possible. Have you tried googling your query? – PeeHaa Jul 22 '13 at 09:35
-
Yes tried but everyone tells about transfer files from where the script runs. That worked for me too..But I'm trying to execute the script in third system for transferring files from src to destination. Can you provide an example script If you've tried? – Jenson M John Jul 22 '13 at 09:39
1 Answers
1
What you want to achieve is called FXP, and you can accomplish this with raw FTP commands:
$ansver = ftp_raw($ftp_conn1, 'PASV');
if (intval($ansver[0]) == 227) {
ftp_raw($ftp_conn2, 'PORT '.substr($ansver[0], $n = strpos($ansver[0], '(') + 1, strpos($m[0], ')', $n) - $n));
ftp_raw($ftp_conn1, 'STOR '.$filename); // need asynchronously (non-blocking)
ftp_raw($ftp_conn2, 'RETR '.$filename);
}

Ja͢ck
- 170,779
- 38
- 263
- 309