Operating System - HP-UX
1753916 Members
7854 Online
108810 Solutions
New Discussion юеВ

Re: FTP commands in the shell scripts

 
SOLVED
Go to solution
Radim Jarosek
Regular Advisor

FTP commands in the shell scripts

Hi everybody,

I need write a scripts with ftp commands.

for example:
------------
#!/usr/bin/sh

cd /home/user1

ftp machine
user_name
passwd
get file
bye

exit 0

------------------

I have no idea how to do it. :-(

I guess that it is so stupid but ...

Could you anyone help me ?

Thanks Radim
9 REPLIES 9
Thierry Poels_1
Honored Contributor

Re: FTP commands in the shell scripts

Hi,
you're already close. Redirect standard input to the ftp command, all following lines will be handled like you would type them until the marker (here EOT) is found.

ftp machine << EOT
user_name
passwd
get file
bye
EOT

good luck,
Thierry
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Radim Jarosek
Regular Advisor

Re: FTP commands in the shell scripts

Hi,

wow, so fast response :-).

I've already tried to use here doc but it didn't work as I excepted. I got to the passwd prompt only.

Radim
federico_3
Honored Contributor
Solution

Re: FTP commands in the shell scripts

Use the following:

/usr/bin/ftp -vn <<-EOF
open "IP or hostname"
uer "username""password "

bin
get file
quit
EOF

federico

Tommy Palo
Trusted Contributor

Re: FTP commands in the shell scripts

Thierry Poels_1
Honored Contributor

Re: FTP commands in the shell scripts

response was toooo fast ;)

ftp -n server << EOT
user theuser thepassword
cd thedirectory
get thefile
bye
EOT
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Radim Jarosek
Regular Advisor

Re: FTP commands in the shell scripts

Hi everybody,

What's surprise! It's working :)

Thanks for your help

Radim

p.s. Points are coming ;)
Nick Wickens
Respected Contributor

Re: FTP commands in the shell scripts

Ok - Heres a challenge - How would you make the password in such an FTP script unviewable ?

I was toying with using crypt somehow but you would still need to have the crypy key available.
Hats ? We don't need no stinkin' hats !!
Kirk Gardner
Advisor

Re: FTP commands in the shell scripts

Or...configure a .netrc macro.
Thierry Poels_1
Honored Contributor

Re: FTP commands in the shell scripts

Hi Nick,
I aggree about the password issue.
I've been thinking about it too; but haven't got any further than creating FTP accounts with very very very limited privileges.
Also the script should be kept away from hungry eyes ;)
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.