====== 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`. {{:50_dialy:2025:05:pasted:20250523-021705.png?300}} {{:50_dialy:2025:05:pasted:20250523-021757.png?400}} ===== 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. @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. 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) [[https://sound.jp/yach/bookmark/data/20120623024927/index.html|WinSCP command options, etc.]] {{tag>diary WinSCP}}