开发者

FTP Error Handling

I have a KornShell (ksh) script which writes out FTP script and executes to get some files from windows server to UNIX.

echo "user <username> <pwd>" >ftpin.out
echo "bin">>ftpin.out
echo "get file.txt" >>ftpin.out
echo "get file2.txt" >>ftpin.out
echo "!echo $?">>ftpin.out
echo"bye">>ftpin.out

ftp -n -i servername <ftpin.out
echo $?

Here I am not able to check if the file exists on the source Windows system or not. Because this usual error handling is not working and the $? is 0 always when any file is there and other is not there. I even tried checking for ERRORLEVEL but tha开发者_如何学Got is not working on UNIX(Solaris 10).

Can any one show samples of simple error handling for this which works or how to do it? Log file parsing was also taken into consideration but is there any other built in way? Other FTP mechanisms are out of scope. We are using plain old FTP.


I don't think reading $? will work. You just get the value from the subshell executed (with the ! command).

I suggest you could take a look at expect: http://expect.sourceforge.net/ It's free and probably available in your Linux distribution's repository.

From the web page:

Expect is a tool for automating interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc.


Thanks for your responses. I am using the below method to make it work.

echo "user <username> <pwd>" >ftpin.out
echo "bin">>ftpin.out
echo "get file.txt" >>ftpin.out
echo "! [ ! -f file.txt ] && ksh alertme.sh" >>ftpin.out
echo "get file2.txt" >>ftpin.out
echo "! [ ! -f file2.txt ] && ksh alertme.sh" >>ftpin.out
echo"bye">>ftpin.out

ftp -n -i servername <ftpin.out

By the above method if FTP fails to copy one file if the file is not present in the source server then i will call alertme.sh script to mail me an error message. This way I can even use it to overwrite the ftpin.out itself to stop the next get of a file in ftp. I am going to test the below one for this.

echo "! [ ! -f file.txt ] && echo bye>>ftpin.out" >>ftpin.out

Thanks again. Hope this helps for any body facing similar difficulty.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜