我可以通过更改文件名逐个发送文件,文件数量也在增加,所以我尝试使用for循环,但它没有用。
我需要将 FILE 变量中的所有文件发送到远程计算机 USER @ $ HOST:/ Semi / KFILE-ENG / ELD 。此外,远程计算机启用了sftp,而发件人仅使用ftp。 这就是我唯一拥有的。
HOST=ftpabc.abc.cn
PORT=22
USER=user
PASSWORD=pass
FILE=/u01/flatringDev/ToVendor/LC7/ELD/ELD.7
spawn /usr/bin/sftp $USER@$HOST:/Semi/KFILE-ENG
expect "password:"
send "$PASSWORD\r"
expect "sftp>"
send "mkdir ELD\r"
expect "sftp>"
send "cd ELD\r"
expect "sftp>"
send "put $FILE\r"
expect "sftp>"
send "bye\r"
如果有人知道解决方案,请告诉我。谢谢
答案 0 :(得分:0)
#!/bin/bash
HOST=ftpabc.abc.cn
PORT=22
USER=user
PASSWORD=pass
declare -a arry
arry=('file1' 'file2' 'file3' 'file4' '/tmp/kl.pl') # list files with absolute path eg: /tmp/kl.pl
#for FILE in $(ls -1 DIR_containing_files) # If you can all files in same dir, else create an array with elements as filenames with absoulte path and use 2nd for statement
for FILE in ${arry[*]}
do
spawn /usr/bin/sftp $USER@$HOST:/Semi/KFILE-ENG
expect "password:"
send "$PASSWORD\r"
expect "sftp>"
send "mkdir ELD\r"
expect "sftp>"
send "cd ELD\r"
expect "sftp>"
send "put $FILE\r"
expect "sftp>"
send "bye\r"
sleep 5
done
检查一下是否有效,您可以bash function
执行expect
所有操作并在for loop
中调用它
或期望脚本文件,并在bash for