General discussion

Locked

SHELL SCRIPT

By avmw ·
CAN ANY BODY TELL THE SCRIPT FOR "ENTER" KEY
that is I want to do ftp from a unix m/c with the script (giving username and password)
adv thanx!!!

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

SHELL SCRIPT

by Skizz In reply to SHELL SCRIPT

A simple script:
ftp hostname << EOF
username
password
get filename
bye
EOF

Collapse -

SHELL SCRIPT

by avmw In reply to SHELL SCRIPT

Poster rated this answer

Collapse -

SHELL SCRIPT

by cpfeiffe In reply to SHELL SCRIPT

Unix ftp is acutally designed to read a macro file - .netrc. If you create the .netrc file in the home directory of the person performing that will be performing the ftp here is the syntax
machine $IP
login $USER
password $PASSWORD
macdef init$COMMANDS
$SPACE
$SPACE

The $IP is the IP address of the machine you are FTPing to. $USER is the account to login with and $PASSWORD is the password for the account. $COMMANDS are the commands to use with FTP (bin, prompt, cd, lcd, put, get, etc.). $SPACE is a blank line. There MUST be two blank lines at the end of each macro.

After building the file just set permissions to 600 (rw-------). It will only work if it is readable and writeable by the owner and only the owner.

Now whenever that user does an ftp to any machine in the .netrc file (identified by machine $IP) it will run the macro instead of an interactive FTP.

This is a way to avoid setting up a script with returns and a good way to run a script to pull datafrom several machines. Just have a cron job call an file that ftp's to one IP address after the other and add a macro to .netrc for each IP address.

Since this removes the ability to perform interactive FTP you may want to create an acocunt just for this purpose or put this file under an account that doesn't need to FTP to this machine interactively.

Good luck.

Collapse -

SHELL SCRIPT

by avmw In reply to SHELL SCRIPT

Poster rated this answer

Collapse -

SHELL SCRIPT

by bkduke In reply to SHELL SCRIPT

Both of the previous replys are correct. You can append stdin responses using << inpath redirection or have ftp read the responses from the .netrc file.

However you need to check the ftp man pages for your own flavor of Unix or Linix. Some require a flag to indicate that ftp is not to attempt to perform an auto-logon. If auto-logon is not enabled, ftp checks for the .netrc file in the users home directory.

The following has worked for me under Sun Solaris.

ftp -v -n foo.bar.com <<EOF
user user123 pwd1%Xa
cd dir1/dir2
put file1.dat
cd ../dir3
put file4.dat
quit
EOF

Collapse -

SHELL SCRIPT

by avmw In reply to SHELL SCRIPT

Poster rated this answer

Collapse -

SHELL SCRIPT

by avmw In reply to SHELL SCRIPT

This question was closed by the author

Back to Linux Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums