Operating System - HP-UX
1827293 Members
3376 Online
109717 Solutions
New Discussion

Simple Automated FTP Scripts

 
Alex St. Amand_1
Occasional Contributor

Simple Automated FTP Scripts

I am in need of an FTP script or utility to transfer a file back and forth from a vendors server on a daily basis. The script/utility would need the capability of checking if the file exists and if it is complete before proceeding (possibly by checking the file size or date).

I am new to Unix scripting, and I admit this is above my abilities (I am an expert from the NT world). However, I am capable of modifying any current script to work.

I am humbly hoping there is a current good script out there or a good utility to accomplish this task.

Thanks Everyone.
8 REPLIES 8
Mark Huff II
Frequent Advisor

Re: Simple Automated FTP Scripts

Well if you had a way of knowing when the file was finished building -- such as a trailer or a second empty file denoting completion.

You could write a script to login a try and get the empty completion file -
If it fails then the file isn't completed.
-
If it succeds then delete the empty completion file and download the other file.

I could give you some example scripts if you need them.
He who fails to plan, plans to fail.
Rita C Workman
Honored Contributor

Re: Simple Automated FTP Scripts

Here is a thread that has a few automated ftp scripts..what you may need to do is add a statement that performs a test or does a loop based on
'if the file exists -f or if the file exists and the size is greater than zero -s '
you can do this in a POSIX shell with a:
test -f /dir/filename or test -s /dir/filename
..OR you could do it with a conditional statment
[[ -f /dir/filename ]] or [[ -s /dir/filename]]

then incorporte the auto ftp statements..

Just something to get you started,
/rcw
Volker Borowski
Honored Contributor

Re: Simple Automated FTP Scripts

Hi Alex,

the easiest way, to be sure that the file is finished, is to rename it after the transmission in your ftp script

ftp> put myfile.intransmission
ftp> rename myfile.intransmission myfile.completed

To have automatic login, check out ".netrc" file.

When you receive the file, you should make a local copy of it, so the next transfer can do a "cmp" to check if it is diffrent.

Just a few guidelines.
Volker


Mike Hassell
Respected Contributor

Re: Simple Automated FTP Scripts

Alex,

Attached is a copy of a script that I've been using to ftp files back and fourth from our servers. It works just fine for the actual portion of doing the ftp for you from a shell script, however it lacks any security features.

Usage: ftp_batch hostname userid passwd get|put src_file dest_file

Looks like Rita's post will take care of determining the status of the file and this will give you the ability to do the ftp. Call this script from your main script and setup that script to run via cron (at in the MS world) and you should be able to accomplish your goal.

- Mike
The network is the computer, yeah I stole it from Sun, so what?
Paula J Frazer-Campbell
Honored Contributor

Re: Simple Automated FTP Scripts

Hi Alex
A simle way to check if build has finished is to get the system time and compare it with the file time.


HTP

Paula
If you can spell SysAdmin then you is one - anon
Paula J Frazer-Campbell
Honored Contributor

Re: Simple Automated FTP Scripts

Hi
Ftp script:-



Remember to exit here if file is not complete.

ftp -n << End_of_Ftp
user
prompt
put
quit
End_of_Ftp


HTH

Paula
If you can spell SysAdmin then you is one - anon
satish_4
New Member

Re: Simple Automated FTP Scripts

Hi Alex,

If remsh is allowed attached script works fine.

You should keep it in crontab for running on daily basis.

Cheers...
Satish.
Bill Hassell
Honored Contributor

Re: Simple Automated FTP Scripts

Be sure to manually record all the steps you use to test and get the file. You can add all of these to your script. Depending on the remote system, you may be able to use the quote and quote site commands in ftp. This can give you some remote controls and information.


Bill Hassell, sysadmin