Operating System - HP-UX
1777111 Members
3182 Online
109065 Solutions
New Discussion юеВ

Having FTP automatically executed

 
Rachid Abrahin neto
Occasional Contributor

Having FTP automatically executed

Hello,
I'm a really green newbie in HP-UX, searching
for a simple way of having a list of commands
automatically executed in FTP. Is there a way
of doing it? Can a "batch" file be passed as
an argument to the FTP command?
Thankful for any help,
Rachid.
3 REPLIES 3
Anthony Goonetilleke_1
Regular Advisor

Re: Having FTP automatically executed

You can use a "HERE" script somthing like this to automate ftp transactions.

#!/bin/sh
SOURCE=$1
ftp -n $SOURCE <ascii
user username password
lcd
get /tmp/crap
EndFTP
Alan Riggs_1
Regular Advisor

Re: Having FTP automatically executed

This type of stdin redirection will work to automate your ftp session.
However, I recommend that you never place a user name and password in a flat
file like this. You can automate an ftp login by editing the .netrc file in
the appropriate user's home directory.

Use "man netrc" for details.
Ric Bradley_2
New Member

Re: Having FTP automatically executed

After you set up your .netrc file (see netrc manpage and remember to chmod 400
.netrc) put some lines something like this in a shell script:

#!/bin/ksh

# Initialize some variables
SOURCE_DIR=your_source_dir_name
TARGET_DIR=your_target_dir_name
TARGET_MACHINE=your_target_machine_name
DATA_FILE=your_data_file_name

# Build ftp command file
echo "bin" > ${HOME}/.commands
echo "hash" >> ${HOME}/.commands
echo "prompt" >> ${HOME}/.commands
echo "cd " ${SOURCE_DIR} >> ${HOME}/.commands
echo "lcd " ${TARGET_DIR} >> ${HOME}/.commands
echo "put " ${DATA_FILE} >> ${HOME}/.commands
echo "quit" >> ${HOME}/.commands

# Do the ftp and log the output
cat ${HOME}/.commands | ftp ${TARGET_MACHINE} > \ /tmp/ftp_log

exit 0

Make the file executable and run it from cron and you're done.