User Tools

Site Tools


Sidebar

Translations of this page:



最近の更新



Tag Cloud

en:50_dialy:2025:05:23

2025.05.23 Synchronizing with WinSCP

How to synchronize a remote folder using WinSCP on Windows.

In this case, we'll connect using key authentication, with everything stored in the `Desktop\Sync` folder.

Desktop\Sync
  sync.bat
  upload.txt
  key.ppk

1. Create an SFTP session in WinSCP

Assume that you have created a connection configuration to `hogehoge.com`.

2. Batch File

Synchronize the local folder `C:\Users\hogehoge\` with the remote folder `sync`.

※ If the path contains Japanese characters, the encoding of `upload.bat` must be Shift-JIS to avoid errors.

upload.bat

@rem sync
set LOCAL="C:\Users\hogehoge\"
set REMOTE="sync"
set SESSION="sftp://matsui@hogehoge.com"
"C:\Program Files (x86)\WinSCP\winscp.exe" /script=upload.txt /parameter %SESSION% %LOCAL% %REMOTE% /console /log=upload.log /privatekey=key.ppk

3. WinSCP Script

※ The `-delete` option deletes files on the remote side that do not exist locally.

upload.txt

option exclude "./03_App/Atom/; ./02_Photos/; */_old/; ./99_*/"
open %1%
lcd %2%
cd %3%
synchronize remote -delete -criteria=time
exit

※ To exclude folders, list them in `option exclude` (use `;` to separate multiple paths)

WinSCP command options, etc.

en/50_dialy/2025/05/23.txt · Last modified: 2025/06/24 09:54 by matsui