
sftpスクリプトがあり、sftpディレクトリを接続してファイルをローカルコンピュータにコピーしようとしています。リモートsftpディレクトリには、ftpからローカルディレクトリにインポートする必要があるファイル名を含む「note.lst」ファイルがあります。
sftp
cd /root/ftp1
lcd /root/foleder1
cat note.lst > ${2}
mget ${2}
bye
上記のコマンドラインでリストファイルをcatし、cat o / pのデータを変数$ {2}に移動してインポートしようとしています。
次の方法は機能しません。誰でも私を助けることができますか?
ありがとうございます。
答え1
これを2つのタスクに分割できます。 1つはリストをインポートし、もう1つはリストされたファイルをインポートすることです。
# Fetch the list
scratch=$(mktemp -d)
trap "rm -fr $scratch" EXIT
scp user@host:/root/ftp1/note.lst $scratch/filelist.txt
# transmogrigy the list into the SFTP script:
awk 'BEGIN{ print "lcd /root/foleder1"; print "cd /root/ftp1" } { print "get \"" $0 "\"" }' > $scratch/script.sftp
# execute the SFTP script
sftp -b $scratch/script.sftp user@host