# Automate FTP Upload



## Gibble (Oct 10, 2001)

I need to write a script that can ftp files to my webserver automatically. 

Please help. 

Basically all I need to know is how I can script FTP Uploads, I don't need the script written I just don't know where to start for that one piece.


----------



## codejockey (Feb 11, 2002)

You could use several methods, including:

(1) re-directing ftp commands from a file or a here document (e.g., ftp < ftpcommands.in). Note that you could also execute the commands directly from a shell script that controls the ftp session.
(2) using tkl/expect
(3) using perl

Hope this helps.


----------



## Gibble (Oct 10, 2001)

I like that first idea...do you have an example?


----------



## codejockey (Feb 11, 2002)

Here's a QND snippet that may be useful. The basic idea is that the script is passed an expression that evaluates to a list of files to transfer (*.htm, for example). All files are placed in the same location on the remote system. Of course, you could make this a lot smarter and put files in different locations or transfer to different systems, etc. Note that the script requires a .netrc file in your home directory to automate the login process for ftp.

ftp mysite.com << EOF
cd somedirectory/location/on/remote
prompt
binary
mput "$*"
bye
EOF

Hope this helps.


----------



## Gibble (Oct 10, 2001)

Yep it appears this will work


----------



## codejockey (Feb 11, 2002)

Hey, Gibble --

Thanks for the reply. Glad it worked out (not the most elegant solution, but at least a starting point). Glad I could post something you found useful.

-codejockey


----------

