我想复制文件从/到远程服务器在不同的目录。 例如,我想一次运行这4个命令。
scp remote:A/1.txt local:A/1.txt
scp remote:A/2.txt local:A/2.txt
scp remote:B/1.txt local:B/1.txt
scp remote:C/1.txt local:C/1.txt
最简单的方法是什么?
我想复制文件从/到远程服务器在不同的目录。 例如,我想一次运行这4个命令。
scp remote:A/1.txt local:A/1.txt
scp remote:A/2.txt local:A/2.txt
scp remote:B/1.txt local:B/1.txt
scp remote:C/1.txt local:C/1.txt
最简单的方法是什么?
当前回答
在我的案例中,有太多名称不相关的文件。
我最后用了,
$ for i in $(ssh remote 'ls ~/dir'); do scp remote:~/dir/$i ./$i; done
1.txt 100% 322KB 1.2MB/s 00:00
2.txt 100% 33KB 460.7KB/s 00:00
3.txt 100% 61KB 572.1KB/s 00:00
$
其他回答
{file1,file2,file3}的答案仅适用于bash(在远程或本地)
真正的方法是:
scp user@remote:'/path1/file1 /path2/file2 /path3/file3' /localPath
问题:使用单个SCP命令将多个目录从远程服务器复制到本地计算机,并保留每个目录在远程服务器中的原样。
解决方案:SCP可以很容易地做到这一点。这解决了在对多个文件夹使用SCP时需要多次输入密码的烦人问题。因此,这也节省了很多时间!
e.g.
# copies folders t1, t2, t3 from `test` to your local working directory
# note that there shouldn't be any space in between the folder names;
# we also escape the braces.
# please note the dot at the end of the SCP command
~$ cd ~/working/directory
~$ scp -r username@contact.server.de:/work/datasets/images/test/\{t1,t2,t3\} .
PS:受到这个伟大答案的激励:scp或sftp用一个命令复制多个文件
根据注释,这在Windows上的Git Bash中也可以正常工作
scp remote:"[A-C]/[12].txt" local:
在特定的情况下,所有文件具有相同的扩展名,但具有不同的后缀(例如日志文件的数量),您可以使用以下方法:
scp user_name@ip.of.remote.machine:/some/log/folder/some_log_file.* ./
这将从远程文件中的给定文件夹中复制所有名为some_log_file的文件,即- some_log_file。1, some_log_file。2, some_log_file。3.
复制多个目录:
scp -r dir1 dir2 dir3 admin@127.0.0.1:~/