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

FTP question

Status
Not open for further replies.

babeo

Technical User
Mar 30, 2000
398
CA
Hi
could anyone show me how to do this please?
I want to have a cron job to do the ftp from 1 Sun box to another and grab files with current date. Everything is put in a script, but I don't know how to make ftp automatically enter username and password at the ftp command. Here is what I want to do:


mySunbox>ftp 123.456.78.90
(enter username is: babeo
password: babeo)
lcd /NewFile
# I want to set the local directory at NewFile to save my
# ftp files in here

cd /TodayFile
# I want to change to the directory TodayFile

mget file$mmdd*
sleep 180
quit
==================
Thanks
 
I'm not at a unix box here, but from memory you need a .netrc file in the home directory of the the user executing the command. This file should have a line containing the machine name, login and password, e.g.

remoteserver joebloggs password

Try a man netrc to see if that helps. I'll post again tomorrow from work if you still need help.

Greg.
 
Hi Greg

I have tried to modify the FTP part in my sript, and add information in the .netrc file. Here it is:

(file .netrc
machine 123.456.78.90 login babeo password babeo)

ftp <<!
open 123.456.78.90
user babeo babeo
quit


But when I run it, I still get error:

Login incorrect.
Login failed.

2) by the way, I set the variable TODAY = date '+%d%m' and substitute TODAY in the command &quot;mget file$TODAY*&quot; will it work?
Thanks
 
Can you post a copy of your script here?

Once you have .netrc created, you don't have to specify any login information to ftp, so you do something like;
Code:
ftp 123.456.78.90 <<!
mget file$TODAY*
!
The line in .netrc will login automatically (assuming you have username & password correct!)

This also assumes you have set the value of TODAY in the shell using TODAY=`date +%d%m`

The mget should work ... in your case (for today) it will get all files matching the pattern file1503*

Post back if you still have problems.

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top