Differences
This shows you the differences between the selected revisions of the page.
| guide_automation 2022-02-19 | guide_automation 2026-06-03 (current) | ||
| Line 1: | Line 1: | ||
| - | |||
| ====== Automate file transfers (or synchronization) to FTP server or SFTP server ====== | ====== Automate file transfers (or synchronization) to FTP server or SFTP server ====== | ||
| Line 26: | Line 25: | ||
| <code winscp> | <code winscp> | ||
| # Connect to SFTP server using a password | # Connect to SFTP server using a password | ||
| - | open sftp://user:password@example.com/ -hostkey="ssh-rsa 2048 xxxxxxxxxxx...=" | + | open sftp://user:password@example.com/ -hostkey="ssh-rsa 2048 xxxxxxxxxxx..." |
| # Upload file | # Upload file | ||
| put d:\examplefile.txt /home/user/ | put d:\examplefile.txt /home/user/ | ||
| Line 36: | Line 35: | ||
| Assemble the commands into a script file. You can name the script file as you like. See [[scripting#example|simple example]] and some [[scripts|useful scripts]]. | Assemble the commands into a script file. You can name the script file as you like. See [[scripting#example|simple example]] and some [[scripts|useful scripts]]. | ||
| - | Use the ''/script'' [[commandline#scripting|command line]] option to pass the script to the WinSCP [[executables|executable]]. Generally, you should also use ''[[commandline#configuration|/ini=nul]]'' switch to [[scripting#configuration|isolate the script execution from GUI configuration]]. You can embed the complete command line into a Windows batch file (''.bat''), like as follows: | + | Use the ''/script'' [[commandline#scripting|command line]] option to pass the script to the WinSCP [[executables|executable]]. Generally, you should also use [[commandline#configuration|''/ini=nul'' switch]] to [[scripting#configuration|isolate the script execution from GUI configuration]] and [[commandline#logging|''/log='' switch]] to enable [[logging|session logging]]. You can embed the complete command line into a Windows batch file (''.bat''), like as follows: |
| <code batch> | <code batch> | ||
| @echo off | @echo off | ||
| - | winscp.com /ini=nul /script=myscript.txt | + | winscp.com /ini=nul /log=myscript.log /script=myscript.txt |
| </code> | </code> | ||
| Line 53: | Line 52: | ||
| * [[ui_file_panel#selecting_files|Select the files]] you want to transfer. | * [[ui_file_panel#selecting_files|Select the files]] you want to transfer. | ||
| * Use one of the file transfer commands: //Upload//, //Download//, //Upload and Delete//, //Download and Delete//. | * Use one of the file transfer commands: //Upload//, //Download//, //Upload and Delete//, //Download and Delete//. | ||
| - | * On the [[ui_copy|transfer confirmation dialog]], setup transfer options (if you need any non·default settings). | + | * On the [[ui_copy|transfer confirmation dialog]], setup transfer options (if you need any non-default settings). |
| * Use the //[[ui_copy#generating_code|Transfer Settings > Generate Code]]// command. | * Use the //[[ui_copy#generating_code|Transfer Settings > Generate Code]]// command. | ||
| * The [[ui_generateurl#script|Generate transfer code]] dialog will appear with the generated script or code template. | * The [[ui_generateurl#script|Generate transfer code]] dialog will appear with the generated script or code template. | ||
| Line 59: | Line 58: | ||
| ===== [[using]] Using script ===== | ===== [[using]] Using script ===== | ||
| Now to make using script easier/automatic you can: | Now to make using script easier/automatic you can: | ||
| - | * Make shortcut to it on desktop to ease execution. Either make shortcut to batch file (''.bat'') or enter full command line to shortcut itself.((Note that it is not possible to use ''winscp.com'' (''.com'' files in general) directly from a shortcut. Call ''winscp.com'' from a batch file or use ''winscp.exe'' with ''[[commandline#scripting|/console]]'' command-line parameter.)) | + | * Make shortcut to it on desktop to ease execution. Either make shortcut to batch file (''.bat'') or enter full command line to shortcut itself.((Note that it is not possible to use ''winscp.==com=='' (''.com'' files in general) directly from a shortcut. Call ''winscp.com'' from a batch file or use ''winscp.exe'' with ''[[commandline#scripting|/console]]'' command-line parameter.)) |
| * If the wrapping batch file takes filename as command line parameter (see [[#parametrized|below]]) you can: | * If the wrapping batch file takes filename as command line parameter (see [[#parametrized|below]]) you can: | ||
| * Make shortcut to it on desktop and use it by dropping files on the icon. Windows automatically run the batch file and passes path to dropped file as command-line parameter. | * Make shortcut to it on desktop and use it by dropping files on the icon. Windows automatically run the batch file and passes path to dropped file as command-line parameter. | ||
| - | * In a similar way you can put the shortcut to the batch file into Explorer’s ‘Send To’ context menu (''C:\Users\username\AppData\Roaming\Microsoft\Windows\SendTo'' in Windows Vista and newer). &winpath &winvista | + | * In a similar way you can put the shortcut to the batch file into Explorer’s ‘Send To’ context menu (''C:\Users\username\AppData\Roaming\Microsoft\Windows\SendTo''). &winpath |
| * [[guide_schedule|Schedule automatic execution]]. | * [[guide_schedule|Schedule automatic execution]]. | ||
| ===== Notes ===== | ===== Notes ===== | ||
| - | When connecting to SSH host, you will need to [[scripting#hostkey|accept its host key]]. | + | When connecting to the SSH host, you will need to [[scripting#hostkey|accept its host key]]. |
| - | When connecting to FTPS or WebDAVS host with [[tls#certificate|certificate]] signed by untrusted authority you will need to verify the certificate. | + | When connecting to FTPS or WebDAVS host with [[tls#certificate|certificate]] signed by an untrusted authority you will need to verify the certificate. |
| ===== [[parametrized]] Modifying the script automatically ===== | ===== [[parametrized]] Modifying the script automatically ===== | ||
| Line 86: | Line 85: | ||
| <code batch> | <code batch> | ||
| - | winscp.com /ini=nul /script=script.tmp /parameter // c:\myfile.txt | + | winscp.com /ini=nul /log=script.log /script=script.tmp /parameter // c:\myfile.txt |
| </code> | </code> | ||
| Line 104: | Line 103: | ||
| rem Execute the script | rem Execute the script | ||
| - | winscp.com /ini=nul /script=script.tmp | + | winscp.com /ini=nul /log=script.log /script=script.tmp |
| rem Delete the temporary script | rem Delete the temporary script | ||