从文本文件中的 URL 在服务器之间传输文件


Transfer files from server to server from urls in a text file

嗨,我想将文件从保存在文本文件中的 url 从一台服务器传输到另一台服务器。我正在使用共享的 linux 主机。目前,此代码适用于从单个 url 传输文件。但是我想从文本文件中加载许多URL。

/* Source File URL */
$remote_file_url = 'http://origin-server-url/files.mp4';
/* New file name and path for this file */
$local_file = 'files.mp4';
/* Copy the file from source url to server */
$copy = copy( $remote_file_url, $local_file );
/* Add notice for success/failure */
if( !$copy ) {
echo "Doh! failed to copy $file...'n";
}
else{
echo "WOOT! success to copy $file...'n";
}

并且文件名和扩展名应从每个 url 中屏蔽。有人可以帮忙吗?

这是一个非常简单的示例,如何做到这一点。

    $remoteFileUrls = [
        'File 1' => 'http://origin-server-url/files.mp4',
        'File 2' => 'http://origin-server-url/files.mp4',
        'File 3' => 'http://origin-server-url/files.mp4',
        'File 4' => 'http://origin-server-url/files.mp4'
    ];
    $localFileUrls = [
        'File 1' => 'files.mp4',
        'File 2' => 'files.mp4',
        'File 3' => 'files.mp4',
        'File 4' => 'files.mp4'
    ];
    foreach($remoteFileUrls as $key => $remoteUrl){
        /* Copy the file from source url to server */
        $copy = copy( $remoteUrl, $localFileUrls[$key] );
        /* Add notice for success/failure */
        if( $copy ) {
            echo "Success'n";
        }
        else{
            echo "Failed'n";
        }
    }