Last Updated: February 25, 2016
·
2.498K
· drgorb

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

1 Response
Add your 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 ·