How to deploy the local changes of a Git repository using FTP on windows command line

I’m working on a small project which makes it necessary to test everything online, so I can not use my local environment for testing. It’s a very annoying task to copy my changes to the online stage file by file. To make this easier I wrote a script which runs on the windows command line (cmd). The concept behind this script is creating a temporary FTP batch file which contains a put command for every file I have changed in my local Git repository. This file will be executed using the built-in FTP command line client of Windows.


:: Save the root path of the git repository to a variable
  1. for /f %%i in ('git rev-parse –show-toplevel') do set REPOPATH=%%i
  3. :: Get all uncommitted changed files from git
  4. for /f %%i in ('git diff –name-only') do (
  5.  :: Add a ftp put command for the changed file to a temporary file
  6.  echo put %REPOPATH%/%%i %%i >> tmpfiles.ftp
  7. )
  9. :: Merge login credentials and the temporary file into another temp file
  10. copy login.ftp+tmpfiles.ftp tmpcopy.ftp
  12. :: Add a ftp quit command at the end of the temp file
  13. echo quit >> tmpcopy.ftp
  15. :: Execute the ftp temp file
  16. ftp -n -s:tmpcopy.ftp *fill-in-your-ftp-host-here*
  18. :: Delete all temp files
  19. del tmpfiles.ftp
  20. del tmpcopy.ftp
  22. :: Done :-)
  23. pause

Please note: Before running this script you need to create a file called „login.ftp“ in the same folder which contains the following three lines:

  1. *your-ftp-user*
  2. *your-ftp-password*