Check file, before FTP

:mad: Hi All,

I have written a script, which will get the file from other server through FTP.

It is working fine, but i want to add a code which should first check, if the file is available in the source system and then do FTP, once successfully completed, it should delete the file.

Is there any way to do so?

Regards,
ACE

  1. check with -f file test
if [ -f "./t1" ]
then
echo "file available"
fi
  1. check the return value of ftp to understand the happening !

i thought of doing same, but only after i connect to Source server using FTP, i can check. In FTP, i cannot use -f option.

You can do a command ftp to do a "ls" to check files on your server and after get your file.

var=$(ftp -n >&1 << EOF
open server
quote user "user"
quote pass "pass"
binary
ls
bye
EOF);echo "$var" > file

I suggest using Perl for this. You can easily do something like that and more.

See examples at my Perl Net::FTP