FTP会话代码在while / for循环中不起作用。怎么解决?

时间:2014-03-11 09:55:42

标签: shell loops unix ftp

我有这样的要求,读取服务器A上存在的文件X的内容并连接到服务器B并获取文件X的内容。

我的代码是

set -x
idFile="/tserver/Ravi/logs/FilesToBeCopied.txt"
while read line
do
echo $line
ftp -in hrserver << ! > FtpLog.log
user ravi welcome1
cd /hrserver/kumar/Images
lcd /tserver/Ravi/logs/FTPFiles/
get $line
quit
done < $idFile

我得到的错误是:

./myScript.sh
+ idFile=/tserver/Ravi/logs/FilesToBeCopied.txt
./myScript.sh: line 13: syntax error: unexpected end of file

尝试使用for循环:

for line in `cat /tserver/Ravi/logs/FilesToBeCopied.txt`;do
echo $line
echo "$line $FileStorageLocation"
ftp -in hrserver << ! > FtpLog.log
user ravi welcome1
cd /hrserver/kumar/Images
lcd /tserver/Ravi/logs/FTPFiles/
get $line
quit
done

我收到同样的错误, 指向文件的最后一行并显示语法错误。

当我尝试通过注释while / for循环来运行相同的脚本时,脚本成功运行并且ftp已完成(这里我是硬编码的行值)。由于我的要求是从文件中读取每一行并执行ftp,我选择了循环。

我不熟悉shell脚本。我的问题是,是否可以在循环中包含FTP命令?如果是这样,你能帮我确定我的代码出错的地方并解决它吗?如果没有,你能为我的要求提供解决方案吗?

0 个答案:

没有答案