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

限于喜欢 提交于 2019-12-19 11:41:14

问题


I have bunch of files in a directory. But I would like to transfer to SFTP server only files starting with either ABC or XYZ. How do I filter these in my mput command?


回答1:


If your files all in current directory:

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

Output (example):

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  



回答2:


Simply use a file mask in sftp put command (or mput alias):

cd /destination/path
put ABC*
put XYZ*

Note that contrary to common command-line ftp client, in OpenSSH sftp the put itself can upload multiple files (and mput is just an undocumented alias to put).



来源:https://stackoverflow.com/questions/44593009/unix-sftp-mput-command-transfer-all-files-with-a-specific-prefix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!