SVN is definitely cool. So I use it for quite all of my projects. Being able to jump back, having a versioned backup, share-coding with others – awesome.

But most of my projects are to run on some kind of webserver. Usually I use my local webserver to test, so I can symlink directly into the projects (and then upload to productive manually). That’s okay for me. But for a recent project I have to test on some remote ftp. So shall I each time commit/update then upload to FTP? And all other team members too? Come on, we are humans, that is stupid repetitive computer work!

So I discovered SVN hooks. These are kind of scripts that can be called each time a SVN repository is changed. Find the directory in path/to/repos/hooks. I found this for my FTP hook: svn2web – it’ll give you all you need to setup the hook. The real cool thing is that you can define the ftp/sftp-behaviour in SVN properties:

svn propset svn2web "sftp:username:password@machine:/path" .

My pre-commit hook looks like this:

#!/bin/bash
export PATH=/usr/local/bin:/usr/bin:/bin
svn2web $1 $2 >> /tmp/svn2web.log || exit 1
exit 0

Be aware of two things:

  1. Install svn2web commands in /usr/local/bin – now you have to export the path variables in the hook script, because it will be called without any path variables (for security reasons)
  2. If the ftp upload fails for whatever reason, the commmit will fail too. That’s what we want, usually, because otherwise we wouldn’t get any feedback on comitting. If you don’t want, just setup the hook as post-commit.

For some reasons my ftp-upload hook wouldn’t work on this stupid test server. I spent quite some time figuring out why and what. It seemed that whenever ftp tried to PUT, the ftp server tried to change to some extended passive mode and would hang there. I found out that when calling the command

epsv

before ftp operations, this wouldn’t happen. So, cool :-)

No related posts.

7 Comments, Comment or Ping

  1. Man, thanks for the time u invested finding this super-useful solution..
    Bye!

  2. i really dont get how to isntall svn2web, i should copy it to /bin ??

  3. Tobz

    Hi, how hard is it to change this for a windows server(visualSVN)?

  4. Wow, that’s great! Thank you.
    I look for this feature for a lot of time, I will try it as soon as possible.

  5. Joe

    Can you provide screenshots of this process? I am not really following it and really need the help?

    Thanks!

  6. Amazing!!
    Really very helpful..

    Thanks

  7. Sanwali

    Can i use the above hook for tortoisehg of mercurial? Cant seem to find one on google :(

    Any help will be highly appreciated

Reply to “SVN Hook – auto-upload to FTP”