f8x7cq
Last Updated: February 25, 2016
·
1.265K
· drgorb
Micha portrait cropped

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

Say Thanks
Respond

1 Response
Add your response

8123
68a976dde51d7d717472875c208d3538

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 ·