WinSCP script













runScript.bat
@echo off
"C:\Program Files\WinSCP\WinSCP.exe" /log=D:\SFTP\WinSCP.log /ini=nul /script=scriptCotent.txt
  winscp path                                                        run log output                           script content



scriptCotent.txt

option batch abort
option confirm off
option transfer binary
open sftp://ftp01:%21%23%25135qet@192.168.167.15/home/ -hostkey="ssh-rsa 2048 dJGjKJiT1nP+g50SyiJp3JscwmqEuQ3LYpFPn0FF6cs="
synchronize remote D:\surceFolder\ /ftpFolder/targetFolder/
exit




ref https://winscp.net/eng/docs/scriptcommand_synchronize#examples
synchronize remote

local > ftp 
synchronize remote D:\surceFolder\ /ftpFolder/targetFolder/

upload only
put D:\surceFolder\*.*  /ftpFolder/targetFolder/




ftp >  local
synchronize local  "D:\targetFolder\"  /ftpFolder/sourceFolder/



Session > Generate Session URL
open sftp://ftp01:%21%23%25135qet@192.168.167.15/home/ -hostkey="ssh-rsa 2048 dJGjKJiT1nP+g50SyiJp3JscwmqEuQ3LYpFPn0FF6cs="


from https://winscp.net/eng/docs/integration_url


Generating URL


You can have WinSCP generate URL using:
  • Session > Generate Session URL/Code command on main window to generate session URL for current session (preferred as it guarantees that SSH host key fingerprint is included in the URL).
  • Manage > Generate Session URL/Code command on Login dialog to generate session URL for selected site.
  • File(s) > File Names > Generate File URL command on main window to generate file URL for files selected in remote file panel.





Moving Files

Supposing you always want to upload all files from the source to the destination folder, you can simply move the files to the destination folder.

You can do this using -delete switch of the put (or get) command. WinSCP deletes the source file, when it is successfully transferred to the destination folder only.

put -delete C:\source\* /dest/












留言

熱門文章