Operating System - HP-UX
1838646 Members
2422 Online
110128 Solutions
New Discussion

Re: Automation of FTP processes

 
Scott E Smith
Frequent Advisor

Automation of FTP processes

I have a series of files that I periodically would like to send via ftp to about two dozen servers. I have used the .netrc file to simplifiy the login process but I need to issue the put/get commands after the login process is done. The "ftp hostname" command returns the FTP> prompt (logged in) but I can't seem to find a way to input the "put filename" command at the ftp prompt. Any ideas? Thanks.
12 REPLIES 12
Andy Monks
Honored Contributor

Re: Automation of FTP processes

Do :-

echo "put nput nquitn" | ftp hostname

Andy
Alan Riggs
Honored Contributor

Re: Automation of FTP processes

The board removes backslashes -- so Andy's post requires newline escapes where it has "n"s. Another way to do it, just for fun, is command line redirection.

ftp hostname << END
lcd directory
put filename
.
.
.
END

I prefer this for potentially long ftp sessions because I find it more readable for future modification/debuging, but that is just a personal preference.

One thing -- both Andy's and my solution assume you have an appropriate .netrc file in place for the ftp user. Otherwise you need to send the user and password strings to the ftp as well. Since your script will be plain text on the box, that would be less than idealfor security purposes.
Andy Monks
Honored Contributor

Re: Automation of FTP processes

Hi Alan,

Thanks for reminding me of that 'little feature'. I already reported it to HP a few weeks ago, when I spotted it. Shame I forgot this time!
Dhanesh Patel
Occasional Advisor

Re: Automation of FTP processes

We are using macdef within the .netrc file:
-----------------------------------------
machine hpbox login userid password xxxxx
macdef init
lcd /extract
mput *
close
bye
<< 'needs blank line at the end'
---------------------------------------
Ralf Hildebrandt
Valued Contributor

Re: Automation of FTP processes

The more advancen solution would be either to use "rsync" for copying the files, perhaps even tunned through ssh to prevent eavesdropping/sniffing of the data.

Another way would be to "GET" the data from the clients (instaead of "PUT"ing it onto them) using the "wget" command. It also offers retries, incremental transfers etc. etc.
Postfix/BIND/Security/IDS/Scanner, you name it...
Dale Christopher
New Member

Re: Automation of FTP processes

Another option that doesn't need the .netrc file...

ftp -n -v hostname >log |&
print -p "user login password"
print -p "put filename"
print -p "quit"

This also allows you to capture the responce of each ftp command after it is processed. It's not as simple as it sounds to do this, but possible if you need a smart ftp script.
Fred Martin_1
Valued Contributor

Re: Automation of FTP processes

Or somthing like this:

(
echo "ftp 000.000.000.000"
echo "user anonymous root"
echo "ascii"
echo "get backup.txt"
echo "delete backup.txt"
echo "bye"
) | ftp -i -n
fmartin@applicatorssales.com
Victor BERRIDGE
Honored Contributor

Re: Automation of FTP processes

Just a question,
Why arent you using rdist command, to me it seems a better alternative...
Regards
Victor
Tim Malnati
Honored Contributor

Re: Automation of FTP processes

I agree that rdist is by far a better solution to performing this type of file distribution. Be sure to use the gnu version of rdist though where it is supported on most every unix flavor (HP's version works with HPUX machines only). The gnu version also expands the available options that you can use. If you are moving data to a windows environment, there is a PC-rdist out there as well.
James R. Ferguson
Acclaimed Contributor

Re: Automation of FTP processes

Scott:

I personally favor, and use, the technique suggested by Dale. I'm a firm believer in scripting production (routine) processes and find that log files that can be keep for a prescribed period are invaluable in operational management. I use a generalized script of the form:

{
echo "open" $HOST
user $WHO $WHOPASS
hash
$ACTION $LOCALFILE $REMOTEFILE
close
} | ftp -i -n -v 2>&1 | tee -a $LOGFILE

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Automation of FTP processes

Scott:

OOPS! The scipt should have an opening quote (") before the word 'open'; no closing quote after 'open'; but a closing quote after 'close' -- to wit: ...close".

...JRF...
Alan Riggs
Honored Contributor

Re: Automation of FTP processes

I agree that scripting and logging production ftp's is a good idea. However, I personally have a real issue with encoding passwords in plaintext scripts. The .netrc can (should) have 400 permissions for the user in question, making it (slightly) better than placing the password in a script which might be more broadly accessed.