简体   繁体   English

使用SCP大量传输文件

[英]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.

相关问题 是否可以在 Python 中使用 SCP 从目录传输文件但忽略隐藏文件或符号链接? - Is it possible to transfer files from a directory using SCP in Python but ignore hidden files or sym links? 使用 os、Popen 和 Paramiko 在 Windows 上使用 Python 进行 SCP 传输文件的问题 - Problems using Python to SCP transfer files on Windows using os, Popen, and Paramiko 使用Fabric在SSH隧道中的SCP文件 - SCP files in a SSH tunnel, Using Fabric Python 使用 pexpect 通过 scp 发送文件 - Python sending files over scp using pexpect 使用python传输文件 - transfer files using python 使用localhost上的python脚本将文件(scp)传输并运行命令从jumpserver到finalserver - Transfer file(scp) and run command from jumpserver to finalserver using python script on localhost 如何使用python中的第三台本地计算机使用scp在两个远程服务器之间传输文件 - How to transfer a file between two remote servers using scp from a third, local machine in python 使用arcpy.gpxtofeature批量转换gpx文件 - Using arcpy.gpxtofeature to convert gpx files en mass 使用python批量删除所有以“ DirsToDelete”开头的文件 - Mass Delete All Files starting with “DirsToDelete” using python 使用密码在python中的SCP - SCP in python by using password
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM