Discussion Locked

Passing arguments in Unix Shell Script

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

In a shell script, I want to be able to "ftp" to a machine and pass the username, password, put command, etc. but whenenver I run the script, it sits there waiting for me to enter the info. I predefined them in the script, but I don't know how to pass them to the ftp command to get them to execute.

Thanks

Paul

4 replies

by rkeckler2000

Try this in your script

ftp computer << EOF
user username passwd
cd /to/a/directory
put files
bye
EOF

by pcammuso

Sorry, this didn't work! I ended up writing the ftp commands to a file as follows

ftp hostname < file.txt

file.txt contains all I needed

Thanks for the repsonse anyway

by ajohn

Paul,
Basically, you need username, password, and the put command. The username and password should be written to the users .netrc file. It should look like this:
default
login whateverusername
password whateverpassword
I think permissions haveto be set to r--------. (chmod 400)
Then, all that is left is the put command. Write out the put command to a file and cat the file piping throu the ftp command.
like this:
echo "put filename" > dummyfile
cat dummyfile | ftp
I think this shouldat least get you started.
John

This discussion is closed to new replies.