FTP check if file exists and log it

Hi,

I need to create a script that checks if a file exists on an offsite server
which only has ftp enabled. I was originally going to use perls Net::FTP
class but the client does not have perl installed nor wants it.

So, I have to use a shell script which logs into the server, then
checks if different files exist in multiple directories.

Basically, all I need to do is check if the file exists in these directories
but redirect output to a log file which I could bring back to my main
server for further processing.

Here's what I have so far:

FtpUser="username"
FtpPswd="mypassword"
HostName="hostname"
FTPFile1="/u/backups/remotefile1"
FTPFile2="/u/backups/remotefile2"

( echo "user ${FtpUser} ${FtpPswd}
ls $FTPFile1
ls $FTPFile2
bye" ) | ftp -n ${HostName}

  1. How can i capture the output of ls to a file either on the remote or
    current server? and (this script will be placed in root's crontab)

  2. Can I place the FTPFile{n} variable assignments into another file,
    and use a while statement to read the lines 1 by 1 ... without having
    to close the connection each time?

Hope I've explained this clearly.

Thank you!
G

---------- Post updated at 05:19 PM ---------- Previous update was at 04:00 PM ----------

Stupid me ... I figured i could just redirect the ftp output to
the local machine at the end of my ftp command.

But, can anyone help me with my 2nd question?

Thanks!
G

Hi,

The only FTP client that I know that can support ls is NcFTP.

Here is an example of the command line you may used :

$DIR_NCFTP/ncftpls -x "-lR" -f $HOME/.ncftp/file_ncftp ftp://IP_ADRESS/DIRECTORY/ > PATH_OF_THE_LOCAL_DIRECTOY_WHERE_YOU_WANT_TO_WRITE_THE_LOG_FILE

I hope this will help you.