SVN Pre-commit Hook FTP Upload in Windows

I've got an SVN repo running on a Windows machine. I need a script that will upload any committed file to a remote web server. I've read up on pre-commit hooks, but I don't know how to actually write the script, or even in what language it should be written in. Seems like the script needs to be a .bat or .exe to run in windows.

Does anyone have a script that will run on a Windows machine? I'm not looking to upload the entire site, but the individual file(s) committed. I want a pre-commit hook because that will give the user feedback should the ftp upload fail.

If you've done this before, please explain the whole process to a newb.


ANSWERS:


A pre-commit hook is used when you want to be able to fail the commit for some reason. Do you really want to fail a commit be cause your FTP site was down, or the disk was full?

You should only use pre-commit scripts to fail stuff that is under the developer's control such as files that are missing required properties, etc. This gives the developer a chance to correct the problem, then resubmit the commit.

A post-commit script still ties up the user's terminal as they wait for it to complete, but the script can fail and notify the user that something failed, but the commit happens anyway. If you want to do this with hooks, you should be doing it with a post-commit hook and not a pre-commit hook.


For what you want to do, hooks aren't a good way to go. What if the user commits a lot of files? Do they have to sit there for ten or so minutes while your hook script executes?

A better idea is to use a continuous build system like Hudson. Hudson will watch your Subversion repository, and can do the FTP task you want every time a user does a commit. With Hudson, you're not tying up the developer as they wait for the hook to complete, and you have a complete log of what happened with every single commit.

In fact, every site should be using a continuous build server. Even if you don't compile code, you still want to run tests against every commit.

Hudson even has FTP and SFTP plugins which may make your task easier to do. And, you can call pre-build and post-build scripts in Hudson, so you have the flexibility to do almost anything your heart desires.

Hudson runs on Windows servers and Unix servers. It is a Java process.


If you're on Windows, and you don't have PowerShell, you should download some scripting language you and use that to write your hooks. The standard batch programming language in the Windows command.exe processor is not very flexible or powerful. Since hooks run on the server, you only have to worry whether or not your hooks run on a single machine. Some programs use client-side hooks and if you write a hook, it must be capable on running on every single system a client might use.


I think you need a post-commit hook.

A svn hook can indeed be any executable or script file. Look here for some samples

You can use the built-in command line ftp client on windows. One way is to put your FTP commands in a text file, which you can generate from a batch file. Example:

echo [username]>ftp.txt
echo [password]>>ftp.txt
echo put [filename]>>ftp.txt
echo quit>>ftp.txt

ftp -s:ftp.txt [server]

Of course, you can also write a program to do this (e.g. in .Net, using the FtpWebRequest class), it doesn't have to be a batch script.



 MORE:


 ? Export SVN repository over FTP to a remote server
 ? Can Subversion replace FTP?
 ? Svn status output to remote server by ftp?
 ? Webpage doesn't update after changing files via FTP
 ? How can I remove a CMS system(php-fusion) from an FTP server?
 ? Find coordinates of every link in a page
 ? Find coordinates of every link in a page
 ? Find coordinates of every link in a page
 ? Link to page coordinates
 ? Maintain Links on a website