Differences
This shows you the differences between the selected revisions of the page.
2011-12-09 | 2011-12-09 | ||
no summary (203.190.151.114) (hidden) | no summary (203.190.151.114) (hidden) | ||
Line 67: | Line 67: | ||
Note that the configuration also includes [[scripting#hostkey|verified SSH host keys]]. | Note that the configuration also includes [[scripting#hostkey|verified SSH host keys]]. | ||
- | |||
- | ===== Example ===== | ||
- | The example below connects to ''example.com'' server with account ''user'', downloads file and closes the session. Then it connects to the same server with the account ''user2'' and uploads the file back. | ||
- | <code winscp> | ||
- | # Automatically abort script on errors | ||
- | option batch abort | ||
- | # Disable overwrite confirmations that conflict with the previous | ||
- | option confirm off | ||
- | # Connect using a password | ||
- | # open sftp://user:password@example.com -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | ||
- | # Connect | ||
- | open sftp://user@example.com -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | ||
- | # Change remote directory | ||
- | cd /home/user | ||
- | # Force binary mode transfer | ||
- | option transfer binary | ||
- | # Download file to the local directory d:\ | ||
- | get examplefile.txt d:\ | ||
- | # Disconnect | ||
- | close | ||
- | # Connect as a different user | ||
- | open user2@example.com | ||
- | # Change the remote directory | ||
- | cd /home/user2 | ||
- | # Upload the file to current working directory | ||
- | put d:\examplefile.txt | ||
- | # Disconnect | ||
- | close | ||
- | # Exit WinSCP | ||
- | exit | ||
- | </code> | ||
- | Save the script to the file ''example.txt''. To execute the script file use the following command. As the script connects the session itself, using the command ''open'', omit the ''session'' command-line parameter. | ||
- | <code> | ||
- | winscp.exe /console /script=example.txt | ||
- | </code> | ||
- | |||
- | For simple scripts you can specify all the commands on [[commandline|command-line]] using ''/command'' switch: | ||
- | <code> | ||
- | winscp.exe /console /command "option batch abort" "open user@example.com" "get examplefile.txt d:\" "exit" | ||
- | </code> | ||
- | |||
- | Instead of using ''open'' command you can also open a session using a [[commandline|command-line parameter]]. Note that in that case session is opened yet before script starts. Particularly ''option'' commands do not apply yet. Generally you should avoid using this method. | ||
- | <code> | ||
- | winscp.exe /console /script=example.txt user@example.com | ||
- | </code> | ||
- | |||