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

How to start an FTP session from a UNIX script 4

Status
Not open for further replies.

Squall1478

Programmer
Sep 20, 2001
5
US
I am trying to build a script to start an FTP session from a UNIX script. The only problem is that IP Address, user, and password information are going to be coming from a text file. Anyone have any idea how to pass this information to the FTP command. (Tried using < and all I get is ?Invalid Command)
 
Obviously you have to supply the information from that file in a way that ftp understands. There are a number of ways to run ftp in a script. This first one assumes you have stored the info from the file into shell variables within your script.


ftp -n $servername <<!
user $username $password
ftp commands
!


If you're storing ftp login information in a file, you may as well store it in the .netrc file. Basically, this file tells ftp what login information to use to connect to a specified machine. Lines in the file have the form ..

machine servername login username password password

Do a man netrc for full info.

If you do this, then, in your script you can say either

ftp servername <<!
ftp commands
!

or

echo &quot;ftp commands
carriage returns important
between commands&quot; | ftp servername

HTH.

Greg.
 
Thanks for the help. I've tried writing a .netrc file but cannot get the permissions correct. Either it says that the .netrc file not correct mode or Permission Denied. Anyone know of what the correct file permissions should be for this file to work correctly?
 
Try 600. I'm told that it won't work with it open any wider.

let us know if you get this working and how you did it. I'm going to be starting to work on the same thing in a couple of days.

Good luck.
 
Agree with bi ... mine is set to 600. If you think about it this is correct, as you don't want anyone else to see your passwords!

Greg.
 
Thanks guys. You're both right. Changed the permissions to 600 and it worked like a charm. THANKS AGAIN!
 
OK, having another issue with this script. I've setup the script like this:
ftp servername <<+
cd directory I want to get the files from
lcd directory i want to put the files
put filename
quit
+
Right now, I'm testing FTPing a file from a directory on one box to a directory on the same box. I try to go to the directory that I think the files should be in after FTPing but nothing's there. Any ideas why? Is my syntax correct?
 
try:

ftp -n servername <<!
put /local/directory/filename /remote/directory/filename
!

Also, try it interactively rather than from within a script, easier to see error messages like that sometimes. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
If you do this ...

cd directory I want to get the files from
lcd directory i want to put the files
put filename

The files are going from lcd to cd when you do a put. Remember;

cd changes directory on the machine you connect to (the remote host)
lcd changes directory on your current machine (the local host)

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top