Push Git to FTP

With some lightweight web-releated project, I often found that pushing a particular Git revision to the production server – forming a Git to FTP bridge – could be a really convenient part of the workflow. For example editing/versioning the theme for this blog is this kind of issue.

Having a custom action pushing git to ftp at your fingertips can simplify production code deployment.

Having a custom action pushing git to ftp at your fingertips can simplify production code deployment.

I’m using SourceTree (for Mac OSX) to manage my Git repositories, which has a “Custom Action” feature fortunately that can execute shell scripts with some parameters passed in about the current repository (actually about the current working copy).

In the meanwhile René Moser made a useful command-line tool to called git-ftp (surprisingly) to perform the same task I outlined above. I’d prefer a GUI setup, though, that is more close to my workflow.

So the only thing left is to hook up these parts together. I’m thinking of writing a step-by-step tutorial here, since I could be exhausting to get these things together for people like me without a reliable knowledge on weird terminal commands and pesky shell scripts.

0. Show hidden files.

Type into terminal (at any location):

1. Install git-ftp (will be installed in /usr/local/bin).

Type into terminal (at any temporary download location):

Or you can check a more complete installation guide at the git-ftp project page INSTALL.md. Not that you’ll need administrator (super user) access for the last command.

2. Add a tiny shell-script (bridge between SourceTree and git-ftp).

Grab (or create) these – gitFtpInit.sh, gitFtpPush.sh – shell script, and put it near you brand new git-ftp installation in /usr/local/bin.

Seems you have to restore the scripts’ chmod to work properly, so make them execuable using chmod.

Thanks, Frédéric.

3. Configure Custom Git to FTP Action in SourceTree.

Open SourceTree Preferences/Custom Actions then Add.
In SourceTree preferences create a custom action by providing some basic setting.

Configure Custom Git to FTP Action in SourceTree

Add a name for the action, a path to the script from step 2., then provide some parameter hooks to the script: $REPO (FTP username) (FTP password) (FTP path).

Note that you not just provide the FTP host but the full FTP path where you want to deploy your code. Something like ftp://<FTP host>/<path to directory>. Also checking Show Full Output is a good idea to see git-ftp responses/process.

4. First run (let git-ftp setup some stuff on FTP)

For the first time git-ftp need to do some setup at your FTP server. So you should run the action with the initialization script gitFtpInit.sh (only for the first time!), so change it temporary in your action definition.

Configure Custom Git to FTP Action in SourceTree

For the first time, you should run the initializer script (gitFtpInit.sh) instead of the push script you’ll be using anyway.

Run the action, see it initialized, be happy.

SourceTree Custom Git to FTP Action with git-ftp

A pretty handy way to launch such action is just by a right click on a particular revision.

You should undo the changes you’ve made in action definition, so write back the script name to gitFtpPush.sh, and done.

Having this you can easily push your latest state of your working copy to the FTP you specified. Be warned that git-ftp expects that no other people (nor you) is going to modify the deployed files in any other way than pushing with this tool (as you can see this stated in Limitations section of the project page).

14 thoughts on “Push Git to FTP

  1. Frédéric

    Hi again !
    Thanks for files !
    I’ve tried your method but I’ve got this error message

    git LocalPath userName Psswd RemotePath (variables are well implemented, that’s just for the example …)
    launch path not accessible
    Completed with errors, see above

    Do I miss something ?
    I’m sorry, I’m a beginner with GIT, Sourcetree …
    Really thanks for your help !

    Reply
    1. eppz Post author

      Probaly the launch path is not accessible. :D
      Double check everything:
      Is git-ftp properly installed at /usr/local/bin/?
      Do you typed the same path at ‘Script to run:’ field /usr/local/bin/gitFtpPush.sh?
      Do you have administrator (super user) privileges?

      Reply
      1. Frédéric

        Hi,
        thanks for your answer !
        I’ve took my time to try to solve my problem.
        Unfortunately, I’ve removed all my install and do it once again.
        I’ve installed homebrew, grep … and then git-ftp but I’ve always got this error :

        git /Applications/MAMP/htdocs/Folder username password ftp://ftp.url.com
        launch path not accessible
        Completed with errors, see above


        Is git-ftp properly installed at /usr/local/bin/? > only an exec file. Is it OK?
        Do you typed the same path at ‘Script to run:’ field /usr/local/bin/gitFtpPush.sh? > Yep! And tried with the Init file for first time.
        Do you have administrator (super user) privileges? > Yep! I’m admin.

        Is there something I need to do on Mountain Lion to install GIT or something else?
        Thanks for your help.
        That drives me crazy :(

        Reply
        1. eppz Post author

          Scripts need to be set executable (I think something gone wrong during downloading):
          chmod +x /usr/local/bin/gitFtpInit.sh
          chmod +x /usr/local/bin/gitFtpPush.sh

          Reply
  2. Frédéric

    Hi,
    I’m sorry but I really not achieve to get your script work :(
    I’ve tried everything but nothing work. I always get this message “launch path not accessible”.
    Do you know what can be the problem ? My Mac install maybe ?
    Thanks for you help.

    Reply
  3. Frédéric

    Hey,
    How are you?
    Your last trick made the stuff works. No “launch path …” anymore !
    Now i’ve got another pblm :

    git /Applications/MAMP/htdocs/XXX username psswd ftp://ftp.XXX.XXX/www/
    Switching directory to repository root at ‘/Applications/MAMP/htdocs/XXX’
    Pushing latest checkout to ‘ftp://ftp.XXX.XXX/www/’ with the given credentials
    /usr/local/bin/gitFtpPush.sh: line 17: /usr/local/bin/git-ftp: is a directory
    Completed successfully

    The files are not updated at all…
    It seems to not work.
    I think I’m really too bad for all this GIT stuffs :D

    Have you already seen that kind of issue ?
    Thanks

    Reply
    1. eppz Post author

      :D
      This is not GIT stuff actually, this is a third party module.
      I can’t see error message in what you posted above.
      If your path were wrong, git-ftp would tell you something about it.

      Is there any files/changes committed anyway?
      Seems there is nothing to push.

      Reply
  4. Pingback: xCode color scheme with a sense | eppz!

  5. Forrest

    I think I am having issues with the correct formatting of the parameters

    I am having the following error (edited for security)
    git ftp://ftp.mysite.com $PATH username mypassword public_html
    launch path not accessible
    Completed with errors, see above

    What is the correct parameter formatting no extra characters?

    $REPO ftp://ftp.mysite.com $PATH username mypassword public_html
    $REPO ftp://ftp.mysite.com $PATH
    $REPO ftp://ftp.mysite.com $PATH (username) (mypassword) (public_html)

    Reply
    1. eppz Post author

      Have you made the scripts accessible?

      Reply
    2. eppz Post author

      Correct formatting is:

      Reply
  6. Banago

    I’ve also written a little PHP script that that does deployments through FTP. It si called PHPloy and is tightly-coupled with Git to determine what which files where edited/added/deleted and uploads them accordingly. You put your FTP details in a deploy.ini file and run just a command to deploy:

    phploy

    You can also deploy to multiple servers at once. And if you have multiple servers configured, you can select to deploy to one of them like this:

    phploy --server staging

    There is more that can be done – check it out on Github: https://github.com/banago/PHPloy

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">