FTP problems

Hi All,

I am ftping to a windows box where i will be going to a specific directory and check whether file is existing or not. If file exists, get the file to my UNIX box else, say that file didn't exist and touch a new file in UNIX box.

Here is what i tried the code:
This is FTP script.

ftp  -n <<EOF
open windowsboxname
user  --> User credintials.
cd FTPT1
pwd
ls
#Somewhere over here i need to check the file existance. If true get the file else touch #a new file,
get $2 $1/"$2"
rename $2 Archive/`date '+%Y_%m_%d'`"_"$2
quit
EOF

$2 is the file.

I am not sure where to include the code in such a way that the new file will be created if file doesn't exist.

Thanks in advance.

One suggestion is to use two ftp sessions

  • first one is used to just get the "ls" on the remote machine & check the existance of filename in the list and display if it not exists.
  • second session will be executed only if the list generated in the first list contain the filename. then do the "get" of teh required files.

Many thanks for the reply. I will give it a try.