Warning! You have JavaScript turned off. For full viewing experience, switch it back on.

In the beginning the Universe was created. This has made a lot of people very angry and is widely regarded as a bad move.

— Douglas Adams

Color sit amet

by Michał 'czesiek' Czyżewski - computer geek, free software enthusiast & tea lover

Mar 10, 2010

back to blog

Scripting lftp for easy repetitive upload

Yeah, I know I shouldn't do this, but don't we all have our quick and dirty ways of doing stuff? Setting up testing environment takes so much time. Time you prefer to spend watching Film Riot, Futurama, [insert your favourite show here].

Most of the time, I test my PHP code on the server. And uploading via FTP using Filezilla requires using a mouse. I was looking for a tool to speed up the process for quite a bit of time. Recently, I've found a pretty neat solution involving lftp, sophisticated file transfer program (that's what the man page says). It can be easily scripted. In about 5 minutes I've written every script that I possibly needed. Below I present the most simple approach:

# somescript.txt
open username:password@ftp.someserver.com
cd public_html
put index.php
put -O resources stylesheet.css

That's it. You can execute the script by typing lftp -f somescript.txt. The script above sends two files (index.php, stylesheet.css) to /public_html/ directory on the server, putting stylesheet.css in resources/ subdirectory.

Remember, kids - do not ever play with matches or production environments.

gravatar

Arne Babenhauserheide

I use lftp in a Mercurial hook to update my files on the server. That way, whenever I commit and push my code, it automatically gets updated on the server (Sometimes I just push it to a backup folder). That way I never have to remember where exactly each website has to be uploaded to - and I use Mercurial for versiontracking anyway, so it isn't *any* additional work :)

Just use the hook

outgoing = lftp -c 'open -e "mirror -R -X .hg/ ABSOLUTER_PFAD_LOKAL RELATIVER_PFAD_FTP" -u USER,PASS ftp://FTP_SERVER '

Longer version (in german): http://draketo.de/deutsch/freie-software/licht/webseiten-aktualisieren-mit-mercurial-und-lftp

Add comment