1820136 Members
3201 Online
109619 Solutions
New Discussion юеВ

ftp in shell script

 
Wilfred Chau_1
Respected Contributor

ftp in shell script

Does any know how to ftp in a shell script?
I tried "user account password" and
"USER & PASS". But I was still prompted
for a password.

I am ftping to a windows server from a HPUX server.
10 REPLIES 10
Kenny Chau
Trusted Contributor

Re: ftp in shell script

Hi,

You can try to use "ftp -i -n" instead.
If can't, put all the commands in a file and use "ftp -i -n < file", eg.

#file
open xxx.xxx.xxx.xxx
user USER PASSWORD
get file
bye

Then in the shell script, put this line:
ftp -i -n < file

Hope this helps.
Kenny.
Kenny
Steven Sim Kok Leong
Honored Contributor

Re: ftp in shell script

Hi,

I had previously written this script for my user for non-interactive file transfers:

=========================================
#!/sbin/sh
ftp -i -n FTP_SERVER <user
put
EOF
=========================================

Hope this helps. Regards.

Steven Sim Kok Leong
Sanjay_6
Honored Contributor

Re: ftp in shell script

Hi Wilfred,

Try this,

ftp -n server_name_or_ip <user user_name password
bin
ascii
put ...
get ..
...
other ftp commands
...
..
bye
EndFTP

Hope this helps.

Regds
harry d brown jr
Honored Contributor

Re: ftp in shell script

Wilfred,

The best ftp scripting I've seen, is something that Clay showed us a while back:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xc88106295e00d6118ff40090279cd0f9,00.html

live free or die
harry
Live Free or Die
Wilfred Chau_1
Respected Contributor

Re: ftp in shell script

I have tried this already..
ftp -vin $rhost <user
cd $scrdir
lcd $destdir
EOF

But it keeps asking me for a password.

I also tried,

ftp -vin $rhost <user
pass
cd $scrdir
lcd $destdir
EOF

Also failed...probably the problem is the other end...an NT server
Steve Steel
Honored Contributor

Re: ftp in shell script

Hi


try


ftp -i -n <open host
user login passwd
pwd
close
bye
EOF

It works for me

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Andrei Petrov
Advisor

Re: ftp in shell script

Hi Wilfred

The easiest way to send USER and PASS from script is .netrc file in users home directory.
#cd
#echo 'machine ftp.xxxx.com login USER password PASS' >> .netrc
#chmod 600 .netrc
#ftp ftp.xxxx.com

Sure Clay's way to write ftp scripts with perl allows more abiliies to trap errors and stuff like that.

harry d brown jr
Honored Contributor

Re: ftp in shell script

Wilfred,

You can't FTP to an NT server, or any M$ system unless that NT system is running an FTP daemon. You'll find some ftp server stuff here for M$ products:

http://www.webattack.com/Freeware/server/fwftpserver.shtml

live free or die
harry
Live Free or Die
Steven Sim Kok Leong
Honored Contributor

Re: ftp in shell script

Hi,

If you are able to see the prompt for a password, then your FTP connection is likely to be established.

What FTP daemon program are you using ie. Microsoft FTP service that comes with IIS (Internet Information Server)?

Or, are you using other third-party FTP daemon programs?

Hope this helps. Regards.

Steven Sim Kok Leong
Wilfred Chau_1
Respected Contributor

Re: ftp in shell script

My problem has been resolved. Thanks all.