Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automatic ftp 1

Status
Not open for further replies.

we2aresame

Technical User
Feb 10, 2003
128
0
0
CA
Can I write a script to ftp some files from one AIX server to another AIX server automatically?Thanks.
 
Yes....u can wite a script and automate it to transfer files
form aix to aix plat form also aix to non aix platforms
no problem

sushveer
IBM certified specialist-p-series AIX5L System Administration
AIX/SOLARIS/WEBSPHERE-MQ/TIVOLI Administrator
 
Thanks, sushveer, can you give me a example.
 
Take a look at the utility "expect" which is available from This is a scripting language that works wonderfully with ftp. We've developed numerous scripts to automate ftp reliably and unattended.
 
Hi
Here is the sample script for ftp'ing files to and from taget node:

#script title: ftp_get.ksh
#To get the files from remote host to local host
#!/bin/ksh
echo "Please enter the path of the file of remote node from where it will be copied to local node"
read ANS
ftp -n <hostname> <<EOJ
user root <root password>
bin
lcd
get $ANS
quit
EOJ
#End of the script

The above script ftp's the file in to the same path as on remote node
------------------------------------------
#script title:ftp_put.ksh
#To put the files from local node directory to remote node dir
#Before executing this script please ensure that u are in right path on your source node from where the file to be transfered to...
#/bin/ksh

echo &quot;Plase enter path of remote node where you want to put the files&quot;
read ANS
ftp -n <remote host name> <<EOJ
user root <password>
bin
cd $ANS
mput <file1> <file2>
quit
EOJ

#End of the script



sushveer
IBM certified specialist-p-series AIX5L System Administration
AIX/SOLARIS/WEBSPHERE-MQ/TIVOLI Administrator
 
One other thing you might want to use is a .netrc file. This file allows automated login. Create .netrc in root's home directory with permissions 600 and owned by root.

Contents should be something like this, one line per remote server:

mahine <hostname or IP address> login <username> password <password>

This avoids leaving root password in your script and keeps it *a bit* safer (if you set permissions properly).

Be warned: You still have your root pw in plain text.

Consider if you really need to do the ftp as root, or whether you can create a dedicated user for the ftp. You can control this futher by giving it minimum group permissions and setting its shell to /bin/false
 
Hi
I agree with richb30 ...I don't suggest to use root password
in the script ...one can use ftp user password and give file access permissions accordingly...I didn't mention this
in my first reply bcoz ...those are alll basics...any unix admin know about that...otherwise he is not all unix admin..

sushveer
IBM certified specialist-p-series AIX5L System Administration
AIX/SOLARIS/WEBSPHERE-MQ/TIVOLI Administrator
 
sushveer - go easy on we2resame, he is obviously not a unix admin, his addy states he is a &quot;TechnicalUser&quot;

We don't want to be classified as know-it-all MS system ppl now, do we? Lets rather help the people instead of trying to prove our superiority.

IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
MS Certified Windblows Rebooter
 
Hi aixmurderer

I am frank and plain guy...I do neither prove superiority nor disregarding others.I will treat always my self I have quantum of knowledge but some others have ocean of knowledge.That's my personality man!...
sorry... You are mistaken!!!!!!!!!!!!!!!!!!

All I try to furnish the better solution as much as I can...but not I never assure the best solution....!
Are you clear about me...!Thanks alot!!

sushveer
IBM certified specialist-p-series AIX5L System Administration
AIX/SOLARIS/WEBSPHERE-MQ/TIVOLI Administrator
 
Thank you, sushveer,aixmuderer, richb30,bobmfdc, no matter what you said, I believed that you want to help others. Have a nice day.
 
to resolve the problem of passwords and the issue of the .netrc files I setup an anonymous ftp user using the sample script in /usr/samples/tcpip anon.ftp. It sets up all the necessary details for you.

Rather than use expect - I don't like to have to maintain any more applications than I have to - I use shell to build a .netrc file and then delete the .netrc file when tht ftp has completed. I also log the progress to a seperate file.

Here is a sample of a program I use to auto distribte files between multiple systems

#!/bin/ksh
#set -x
########################################################################
# tcp_trans sript to globally transport file via ftp #
#
########################################################################
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
#
#
PASSWORD=&quot;{enter password for systems here}&quot;
# #
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
USAGE='tcp_trans [put/get] [file to be sent] [file to be received]'
if [[ $# -lt 3 ]]
then
echo $USAGE
exit 1
fi
indx=1
touch ~/.netrc
chmod 600 ~/.netrc
cat /dev/null > ~/.netrc
cat /dev/null > tcp_transport_log
file=/home/scripts/translist
# translist is a file containing the list of systems to ftp
# to one system per line.
exec < $file
indx=1
while read line
do
# build first stage
chmod 600 ~/.netrc
cat /dev/null > ~/.netrc
MACTOGO=$line
LOCTOGO='machine '$line' login root password '$PASSWORD' macdef init'
FILETOGO=&quot;$1 &quot;$2
case &quot;$1&quot;
in
put) FILETOGO=$FILETOGO' '$3;;
get) FILETOGO=$FILETOGO' '$line$3;;
esac
FILETODELETE='delete '$3
echo $LOCTOGO >> ~/.netrc
echo &quot;&quot; >> ~/.netrc
echo 'macdef init' >> ~/.netrc
#echo 'ascii' >> ~/.netrc
echo 'binary' >> ~/.netrc
#echo 'hash' >> ~/.netrc
echo $FILETODELETE >> ~/.netrc
echo $FILETOGO >> ~/.netrc
echo &quot;site chmod 755 $3&quot; >> ~/.netrc
### echo &quot;site chmod 644 $3&quot; >> ~/.netrc
echo 'close' >> ~/.netrc
echo 'quit' >> ~/.netrc
echo &quot;&quot; >> ~/.netrc
echo &quot;&quot; >> ~/.netrc
#
# now the transportation work begins

chmod 400 ~/.netrc
echo $MACTOGO
echo $MACTOGO >> tcp_transport_log
/bin/date >> tcp_transport_log
ftp -v $MACTOGO 1>>tcp_transport_log 2>>tcp_transport_log
#ftp -v $MACTOGO
done
rm -r ~/.netrc


A second method is to NFS mount the the directory to the sending system and cp the files. I have found this to be faster than FTP between systems. I copy between 96 and 102 files betwteen system nightly using this method.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top