Automated FTP

My requiremnet is to write a FTP script which will ftp a file to a specified ftp url.
How can I automate the process usnig the unix cron.

Try something like this for the ftp script:

#!/usr/bin/ksh
ftp -v -n "YOUR.IP.ADD.RESS" << cmd
user "user" "passwd"
cd /distant/directory
lcd /local/directoryget ssh_install
get ( or put) your files
quit
cmd

All you have to do after is to create the cron

Will that help?

Jason

It was great.
It worked fine.

Milind.

How can we get the exit status of this script so that we know if the ftp was successful? echo $? always returns 0 in this or similar script. I have a similar script which uploads a file to an ftp site but the exit status always returns true whether the file to be uploaded exists or not.

You can write a smilar FTP script.
if you are "putting" a file,
replace the put with ls and see if your file is in there.
if you are "getting" a file,
search for the file in your local directory and you can then
know if the FTP was successfull or not.

I have posted my script as a new thread under the following heading:

Checking the exit status of ftp

The exit status of that script always returns true whether the ftp is successful or not.

Thanks all..
even I was looking for automatic FTP and it worked for me too.
however I still have one problem as how can I FTP all directories with thier respective sub-directories between two hosts.

Its possible as of now but the structer of the directory has to be existing before, so that FTP can put all the files in their respective sub-directories by saying "mget *". But if the directory structure does not exists then FTP "mget *" command only gets files from home to home and not sub-directories and the files existing in the respective sub-directories.

can you all please help ? is there any way ?
Thanks and Regards
Taher

For the first time I would suggest creating a tar file of the original, ftp it over and create the same directory structure using the tar file.

This could be one of the solution for estimating accurately as to whether a file has been successfully transfered or not via a ftp session, as requested by "psingh".

Following is the script that can do so :

Create and store following details in a separate file
vi ftpdata
Enter the following details
o "Address"
user "username" "password"
get file1
Save and quit from the file

Now in a separate shell script file write the following command:
ftp -v < ftpdata > ftpdata.out 2> ftpdata.out
Now check for the following string in the ftpdata.out file by the grep command:
"Transfer Complete" or "Tansfer Successful"
Presence of it would hence mean that the transfer was success else was a complete failure.

Now using this technique one can easily design in new of transfering multiple files via ftp session and know accurately whether the file was successfully transfered or not.

Hi RTM
thanks for your reply..yes what i understand from what you have suggested is that take a tar of the complete directory structure on a tape. then extract that tape on the other host manually and then start FTPing the complete directory structures..

I tried the same above and now i can FTP all the files with sub-direcotories..
however what i feel is that FTP cannot itself create sub-direcoties while FTPing...is that rite ?

thanx and regards
Taher

You can also automate this using the batch file(bat) in DOS. Even that works nicely. I used it for my work.

-Nisha

In Unix if u r looking for a completely automated ftping process, i feel its not possible , not possible simply because the ftp process does not return a valid exit status, an exit can occur due to many reasons and if u r to monitor whats happening then u cannot call it an automated ftp session. The only way out that i found especially when ur ftping takes place for hours,was to use another software called ncftp,which worked wonderful for me.

These r the status codes returned from 0- 12
Success.
Could not connect to remote host.
Could not connect to remote host - timed out.
Transfer failed.
Transfer failed - timed out.
Directory change failed.
Directory change failed - timed out.
Malformed URL.
Usage error.
Error in login configuration file.
Library initialization failed.
Session initialization failed.

which the normal ftp application does not.

This will solve the problem

Carlos