Unix sftp - mput 命令 - 传输具有特定前缀的所有文件

Unix sftp - mput command - transfer all files with a specific prefix

我的目录中有一堆文件。但我只想将以 ABCXYZ 开头的文件传输到 SFTP 服务器。如何在我的 mput 命令中过滤这些?

如果你的文件都在当前目录:

sftp user@server << EOF
cd /destination
$(for i in ABC* XYZ*; do echo "put $i"; done)
EOF

输出(示例):

Connected to server.
sftp> cd /destination
sftp> put ABCfoo.txt
Uploading ABCfoo.txt to /destination/ABCfoo.txt
ABCfoo.txt                                                                100%    0     0.0KB/s   00:00    
sftp> put XYZfoo.txt
Uploading XYZfoo.txt to /destination/XYZfoo.txt
XYZfoo.txt                                                                100%    0     0.0KB/s   00:00  

只需在 sftp put 命令(或 mput 别名)中使用文件掩码:

cd /destination/path
put ABC*
put XYZ*

请注意,与常见的命令行 ftp 客户端相反,在 OpenSSH sftpput 本身可以上传多个文件(而 mput 只是一个未记录的别名put)。