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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Giving a file to a ftp job

Status
Not open for further replies.

banana

IS-IT--Management
Jan 11, 2001
1
CA
HI All, I would like to automate an ftp session, giving it the contents of a file to execute instead of typing the commands myself... this is to automate the download of files from a server to an other from the web... is this a simple way to do this from a shellscript point of view? I'm on Solaris 2.5.1 at present... thanks in advance.
 
banana,

The ftp command itself can accept a file of commands. Do a man ftp to get full details, but simply put, a file name can be specified by the -s switch. You also need to think how you intend to logon to the remote machine (unless you're using anonymous ftp).

So if you have a file ftpfile, the command would simply be ftp -s:ftpfile.

The contents of ftpfile might look like;
Code:
open servername
put file1
bin
put file2
quit

If you need any more info about logging on etc., I'd be happy to explain. It's worth double checking what I've mentioned above anyway as I'm doing it from memory.

Greg.
 
You can alos try this method :
ftp -i -n -v destination_name < /exploit/input_file
and your input file would loook like this :
user username password
put filename
quit


The flags specified work for Sun Solaris, cant garantee other os

Hope this helps
 
... which also reminds me ... It can be done without an input file at all, in that you can put an ftp wrapper around the ftp commands themselves and treat the file as a standalone shell script. So you may have a shell script which contains something like ..
Code:
ftp <<!
open servername
user username password
put file1
put file2
quit
!
Obviously this isn't a suitable solution if you have a dynamic list of files to transfer.

Greg.
 
Hi !

You can also try creating a .netrc file in the users homedirectory ,a template of .netrc is as follows

machine <hostname> login <loginid> password <passwd>
macdef init
bin
put filename1 filename2
...
bye
endmac
<blank line>


After creating the .netrc in the users homedirectory ,
just say
$ ftp <hostname>

The ftp happens automatically ,
I have tried this on AIX , i am not sure on solaris!!
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top