Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用scp的传质文件_Python_Linux_Perl_Batch File - Fatal编程技术网

Python 使用scp的传质文件

Python 使用scp的传质文件,python,linux,perl,batch-file,Python,Linux,Perl,Batch File,我正在尝试将大量数据从一台服务器传输到另一台服务器。我试过使用 scp <file> <address@server:/path/to/scp/to scp如果要压缩和传输目录中的所有文件,可以使用以下方法: tar -cf - <DIR>/* | sshpass -p '<password>' ssh <address@server> 'tar -xf - -C /path/to/unzip/to' 为cd中的每个目录执行脚本: fo

我正在尝试将大量数据从一台服务器传输到另一台服务器。我试过使用

scp <file> <address@server:/path/to/scp/to

scp如果要压缩和传输目录中的所有文件,可以使用以下方法:

tar -cf - <DIR>/* | sshpass -p '<password>' ssh <address@server>  'tar -xf - -C /path/to/unzip/to'
为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
以$mydirs表示的i的
;
做
echo“压缩目录($i)…”;
tar-cf-/*| sshpass-p''ssh'tar-xf--C/path/to/unzip/to'
完成

我建议使用。NcFTP服务器是您所需要的。当您必须在服务器之间传输文件时,它工作得既快又好。

rsync
是一个不错的选择。它支持ssh,也支持压缩。检查manrsync

SCP的一个常见问题是,它不会对请求进行管道化处理,因此,在传输大量小文件时速度可能非常慢

正如@FlyingFrog已经提出的,这可以通过使用
tar
来解决

从Perl中,您可以轻松地使用它,它还可以处理密码身份验证

use Net::OpenSSH;
my $ssh = Net::OpenSSH->new($host, user => $user, password => $password);
$ssh->system({ stdin_file => ['-|', 'tar', 'czf', '-', @files] },
             "cd $dest && tar zzf - ");

它实际上并不压缩文件。您必须向tar命令(或任何其他压缩方法)添加
z
。我在
manscp
中看到
-C
选项。您尝试过吗?为了避免每次输入密码,请查找ssh密钥验证。请查看
rsync
,它附带了部分传输和更多功能。
use Net::OpenSSH;
my $ssh = Net::OpenSSH->new($host, user => $user, password => $password);
$ssh->system({ stdin_file => ['-|', 'tar', 'czf', '-', @files] },
             "cd $dest && tar zzf - ");