在第三个系统上执行脚本时,PHP FTP会将文件从一台服务器传输到另一台服务器


PHP FTP transfer files from one server to another while executing the script on third system

好吧,我正在尝试使用PHP FTP函数将文件(+目录)从一个服务器(源)传输到另一个(目标)&从第三系统执行脚本。有可能吗?有人能举个例子吗?

您想要实现的被称为FXP,您可以使用原始FTP命令来实现这一点:

$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);
}