1758295 Members
2205 Online
108868 Solutions
New Discussion юеВ

shell script

 
Fredy Correa
Advisor

shell script

good afternoon.. do I need to make a shell to connect me for ftp to a server and to make a get to a file I specify, can they tell me as giving him the parameters so that it is connected, copy and then it is disconnected???

thank you...
9 REPLIES 9
Alan Meyer_4
Respected Contributor

Re: shell script

check out this thread, substitute a get for the put, but everything else is pretty close to the same.

http://forums2.itrc.hp.com/service/forums/questionanswer.do?threadId=937577
" I may not be certified, but I am certifiable... "
Dave La Mar
Honored Contributor

Re: shell script

Fredy-
There are a tone of examples if use the search function of the forumns.

Here is one of a dozen ways to do this:

#! /usr/bin/ksh

date > /home/ftp.log
ftp -n -v << EOF >> /home/ftp.log
open servername
user username password
put /home/TEST.JOB
quit
EOF

exit

The log file will containe the results snd output of the job.
the EOF signifies to perform all instructions until the next occurrence of EOF.
While this uses a hard coded servername, username, password, it is preferable to use a .netrc file for these values. Man .netrc.

Best of luck.

Regards,
dl
"I'm not dumb. I just have a command of thoroughly useless information."
Devesh Pant_1
Esteemed Contributor

Re: shell script

Here is something that you might like

#!/bin/sh
HOST='ftp.users.abc.net'
USER='yourid'
PASSWD='yourpw'
FILE='file.txt'

ftp -n $HOST <quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0

A. Clay Stephenson
Acclaimed Contributor

Re: shell script

You could but the attached Perl script makes this a trivial execise.

Invoke as perl ftpget.pl -u for full usage. If you create a .netrc file, it will automatically read the password or you can pass it on the command line.

ftpget.pl -h remotehost -l mickey -p topsecret -B -d /xxx/yyy file1 file2
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "All was well"
else
echo "FTP failed; status ${STAT}" >&2
fi

Error checking, retries, are built right in.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: shell script

By the way, all of these Mickey Mouse scripts that do no error checking would result in somebody being yelled at if they dropped them on my desk.
If it ain't broke, I can fix that.
Mr Gunyon
Occasional Contributor

Re: shell script

I guess god has spoken
Dave La Mar
Honored Contributor

Re: shell script

Excuse me, I failed to state whAt I "thought" was obvious. The error checking we use comes between the quit and the exit. All error checking is done against the ftp.log file.

#! /usr/bin/ksh

date > /home/ftp.log
ftp -n -v << EOF >> /home/ftp.log
open servername
user username password
put /home/TEST.JOB
quit
EOF
"ERROR CHECKING LOGIC GOES HERE"
exit

Unfortunately, there is little perl scripting used here and this is our primary skeleton of an ftp, except as noted, we will use a .netrc and eliminate the hardcoding mentioned before.


Best of luck.

Regards,

dl
"I'm not dumb. I just have a command of thoroughly useless information."
A. Clay Stephenson
Acclaimed Contributor

Re: shell script

Yes, but you still have to parse the log file and that is a non-trivial task AND you did issue commands w/o checking the status of each. That's why Perl's Net::FTP is so nice; all you have to do is look at the status value and if it's 2 (FTP for good) then all is well. I will concede that you at least gathered a log file.

If it ain't broke, I can fix that.
Muthukumar_5
Honored Contributor

Re: shell script

Use this script available in,

http://forums2.itrc.hp.com/service/forums/questionanswer.do?threadId=940553

hth.
Easy to suggest when don't know about the problem!