列表中的 SSH SCP 文件

问题描述 投票:0回答:3

我有一个需要从远程服务器复制的特定文件列表。这对于 SCP 来说可能吗?

我知道我可以使用

scp {user_name}@{host}:{filepath} .
复制单个文件,但是有没有办法使用
.csv
.txt
并运行 foreach 循环?

ssh scp
3个回答
9
投票
while read file; do scp "user@host:$file" .; done <  files

2
投票

我发现使用 tar 和列表然后通过 scp 单独发送文件更容易:

tar -czvf archive.tar.gz -T file-list.txt && scp archive.tar.gz user@host:/path/

我在没有可用 rsync 的系统上使用此功能,这样您还可以避免重复密码提示或 TCP/SSH 连接限制。


0
投票
scp `cat /path/to/file` login@remote_host
© www.soinside.com 2019 - 2024. All rights reserved.