Shell script FTP commands
I have long wondered how to create a script which does two trivial looking things.
* log in to an ftp server
* upload a local file (or list of files)
* close the connection
I found out today:
#!/bin/sh
HOST='ftp.users.qwest.net'
USER='yourid'
PASSWD='yourpw'
FILE='file.txt'
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0
the trick is to use -n
with the FTP
command and then typing into the FTP shell with quote
There is no error handling. You can find some advice here where I copied the trick myself
Written by Micha Roon
Related protips
1 Response
This is okay for personal or test use. To include error handling, I would typically use expect - http://en.wikipedia.org/wiki/Expect.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ftp
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#