问题
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