[英]Mass transfer files using scp
I'm trying to transfer large quantities of data from one server to another. 我正在尝试将大量数据从一台服务器传输到另一台服务器。 I've tried using
我试过使用
scp <file> <address@server:/path/to/scp/to
Which works, however it's quite slow for large files and requires that I enter a password for each scp. 可以,但是对于大文件来说速度很慢,并且要求我为每个scp输入一个密码。
I've also tried zipping and unzipping before and post transfer but it's even slower. 在传输前后,我也尝试过压缩和解压缩,但速度甚至更慢。 Is there faster way?
有没有更快的方法?
Is this the best way to transfer large amounts of data? 这是传输大量数据的最佳方法吗?
rsync
is a good option. rsync
是一个不错的选择。 It supports ssh as well as it support compression too. 它支持ssh,也支持压缩。 Check
man rsync
检查
man rsync
If you want to compress and transfer all files in a directory you can use this: 如果要压缩和传输目录中的所有文件,可以使用以下命令:
tar -cf - <DIR>/* | sshpass -p '<password>' ssh <address@server> 'tar -xf - -C /path/to/unzip/to'
This will compress all files, transfer via ssh (auto-fill password) and unzip them in a specified path on your second server. 这将压缩所有文件,通过ssh(自动填充密码)传输,并将其解压缩到第二台服务器上的指定路径中。
You could put this in a bash script as follows: 您可以将其放在bash脚本中,如下所示:
Show all dirs in cd and set as $mydir: 显示cd中的所有目录并设置为$ mydir:
mydirs=`ls -p | grep "/"`
Execute script for each dir in cd: 为cd中的每个目录执行脚本:
for i in $mydirs;
do
echo "Zipping directory ($i)...";
tar -cf - <DIR>/* | sshpass -p '<password>' ssh <address@server> 'tar -xf - -C /path/to/unzip/to'
done
One common problem with SCP is that it doesn't pipeline requests, and so, it can be very slow when transferring lots of small files. SCP的一个常见问题是它不对请求进行管道传输,因此,在传输大量小文件时可能会非常慢。
As @FlyingFrog has already sugested, that can be solved using tar
. 由于@FlyingFrog已经提示,可以使用
tar
解决。
From Perl you can do it easyly using Net::OpenSSH which can also handle the password authentication. 在Perl中,您可以使用Net :: OpenSSH轻松完成此操作,它还可以处理密码身份验证。
use Net::OpenSSH;
my $ssh = Net::OpenSSH->new($host, user => $user, password => $password);
$ssh->system({ stdin_file => ['-|', 'tar', 'czf', '-', @files] },
"cd $dest && tar zzf - ");
I would recommend using http://www.ncftp.com/ . 我建议使用http://www.ncftp.com/ 。 NcFTP server is what you need.
您需要NcFTP服务器。 It works fast and best when you have to transfer files between servers.
当您必须在服务器之间传输文件时,它可以最快,最好地工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.