我想复制文件从/到远程服务器在不同的目录。 例如,我想一次运行这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
最简单的方法是什么?
当前回答
从远程复制多个文件到本地:
$ scp your_username@remote.edu:/some/remote/directory/\{a,b,c\} ./
从本地复制多个文件到远程:
$ scp foo.txt bar.txt your_username@remotehost.edu:~
$ scp {foo,bar}.txt your_username@remotehost.edu:~
$ scp *.txt your_username@remotehost.edu:~
从远程复制多个文件到远程:
$ scp your_username@remote1.edu:/some/remote/directory/foobar.txt \
your_username@remote2.edu:/some/remote/directory/
来源:http://www.hypexr.org/linux_scp_help.php
其他回答
从远程复制多个文件到本地:
$ scp your_username@remote.edu:/some/remote/directory/\{a,b,c\} ./
从本地复制多个文件到远程:
$ scp foo.txt bar.txt your_username@remotehost.edu:~
$ scp {foo,bar}.txt your_username@remotehost.edu:~
$ scp *.txt your_username@remotehost.edu:~
从远程复制多个文件到远程:
$ scp your_username@remote1.edu:/some/remote/directory/foobar.txt \
your_username@remote2.edu:/some/remote/directory/
来源:http://www.hypexr.org/linux_scp_help.php
scp -r root@ip-address:/root/dir/ C:\Users\your-name\Downloads\
使用-r可以下载远程服务器的dir目录下的所有文件
SCP使用SSH进行数据传输,并提供与SSH相同的身份验证和安全性。
这里的最佳实践是实现“SSH密钥和公钥身份验证”。这样,您就可以不用担心身份验证就可以编写脚本。就这么简单。
看看什么是SSH-KEYGEN
你可以使用-r开关复制整个目录,所以如果你可以把文件隔离到自己的目录中,你可以一次复制所有的文件。
scp -r ./dir-with-files user@remote-server:upload-path
scp -r user@remote-server:path-to-dir-with-files download-path
例如,
scp -r root@192.168.1.100:/var/log ~/backup-logs
或者如果只有几个,你可以用:
scp 1.txt 2.txt 3.log user@remote-server:upload-path
{file1,file2,file3}的答案仅适用于bash(在远程或本地)
真正的方法是:
scp user@remote:'/path1/file1 /path2/file2 /path3/file3' /localPath