1835085 Members
2451 Online
110073 Solutions
New Discussion

FTP Using Shell script

 
Damu
Occasional Contributor

FTP Using Shell script

Hi all

I wants to write a Shell script which can be connected to a remote ftp server with a user name (not anonymous).

Can any one help me how to write the script for entering a user name and password for the ftp server

cheers
5 REPLIES 5
Arunvijai_4
Honored Contributor

Re: FTP Using Shell script

Hi Damu,

Check this thread for FTP Script,

http://forums1.itrc.hp.com/service/forums/bizsupport/questionanswer.do?threadId=989518
http://forums1.itrc.hp.com/service/forums/bizsupport/questionanswer.do?threadId=811436

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
A. Clay Stephenson
Acclaimed Contributor

Re: FTP Using Shell script

Doing FTP transfers in the shell is very tedious if you do it right because error checking is tough to do. It's much easier to use Perl's Net::FTP module. The attached script will do everything for you and all you need is a little shell scripting ability.

ftpget.pl -h remotehost -l username -p topsecret -d /var/tmp -A myfile1 myfile2
STAT=${?}

if [[ ${STAT} -eq 0 ]]
then
echo "OK"
else
echo "FTP failed; status ${STAT}" >&2
fi

This will login to host "remotehost" as user "username", password "topsecret", cd to /var/tmp, enter ASCII mode (-A); and finally get myfile1 and myfile2. If it exits with a zero status then all is well.
If you need to do a put search for "ftpput.pl".

Invoke as ftpget.pl -u for full usage.

If it ain't broke, I can fix that.
Jeong-Hwan Kim_1
Occasional Advisor

Re: FTP Using Shell script

you can simply do the following on you log-in shell.

#/usr/bin/ksh
################################3
ftp -n xxx.xxx.xxx.xxx << EOF
user anonymous xxx@yyy.com
bi
cd ${target_dir}
put ${source} ${target}
bye
EOF

Good Luck ~~
Antonio Cardoso_1
Trusted Contributor

Re: FTP Using Shell script

Hi,

here is a script I use to send one or more files to a remote ftp server.

syntax is:
sendftp [-p ] file1 file2...

user and pw are given as parameters of script.
path parameter is optional (remote user's home dir will be used as default)

hope this helps.
antonio.
Damu
Occasional Contributor

Re: FTP Using Shell script

I done it by simple script by collecting the all details from the replays