SHELL SCRIPT
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!!!
Linux
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!!!
by skizz
A simple script:
ftp hostname << EOF
username
password
get filename
bye
EOF
by avmw
by cpfeiffe
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.
by avmw
by bkduke
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 <
by avmw
by avmw
This discussion is closed to new replies.
Sort by Trending