Skip to content

Instantly share code, notes, and snippets.

@mildronize
Created February 13, 2017 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mildronize/d0ed0433ff24205bcf6bbbfc64d7ae90 to your computer and use it in GitHub Desktop.
Save mildronize/d0ed0433ff24205bcf6bbbfc64d7ae90 to your computer and use it in GitHub Desktop.
[Windows] Auto upload files changed to remote host
:: Name: auto_sync_to_remote.bat
:: Purpose: Auto upload files changed to remote host without removing any remote files
:: Author: Thada Wangthammang <mildronize@gmail.com>
:: Revision: 2017/02/13 Initial version
:: Ref: http://steve-jansen.github.io/guides/windows-batch-scripting/part-10-advanced-tricks.html
:: http://schier.co/blog/2013/03/13/start-virtualbox-vm-in-headless-mode.html
:: Prerequisite
:: - `Winscp`
:: - `PuttyGen` for creating Putty Private Key
:: Setup parameters
:: [Host] Your hostname
:: [Port] Your hostname's port | Default: 22
:: [User] Your ssh username
:: [PuttyPrivateKeyPath] Putty Private Key Path. | Ex. C:\Users\mildronize\Documents\gits\hostA.ppk
:: [LocalPath] Absolute Local Path | Ex. C:\Users\mildronize\Documents\gits
:: [RemotePath] Absolute Remote Path | Ex. /home/mildronize/gits
:: [Timeout] time out for establishing ssh connection in seconds | Default: 5
:: Warning:
:: ** While generating Putty private key, passphrase should be provided!
@ECHO OFF
SET Host=
SET Port=22
SET User=
SET PuttyPrivateKeyPath=
SET LocalPath=
SET RemotePath=
SET Timeout=5
SET HostKey="*"
winscp.com /command ^
"option batch abort" ^
"option confirm off" ^
"open sftp://%User%@%Host%:%Port% -privatekey=%PuttyPrivateKeyPath% -hostkey=%HostKey% -timeout=%Timeout%" ^
"synchronize remote %LocalPath% %RemotePath% " ^
"keepuptodate %LocalPath% %RemotePath% " ^
"exit"
EXIT /B 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment