Differences
This shows you the differences between the selected revisions of the page.
| faq_batch_file 2020-04-17 | faq_batch_file 2023-01-16 (current) | ||
| Line 10: | Line 10: | ||
| echo Starting WinSCP | echo Starting WinSCP | ||
| winscp.com /log=winscp.log /ini=nul | winscp.com /log=winscp.log /ini=nul | ||
| - | open sftp://username:password@example.com/ | + | open sftp://user:password@example.com/ |
| put d:\examplefile.txt | put d:\examplefile.txt | ||
| exit | exit | ||
| Line 21: | Line 21: | ||
| * With ''/script'' switch, you need to move your WinSCP commands into a separate text file, e.g. ''script.txt'': \\ <code winscp> | * With ''/script'' switch, you need to move your WinSCP commands into a separate text file, e.g. ''script.txt'': \\ <code winscp> | ||
| - | open sftp://username:password@example.com/ | + | open sftp://user:password@example.com/ |
| put d:\examplefile.txt | put d:\examplefile.txt | ||
| exit | exit | ||
| Line 33: | Line 33: | ||
| echo Starting WinSCP | echo Starting WinSCP | ||
| winscp.com /log=winscp.log /ini=nul /command ^ | winscp.com /log=winscp.log /ini=nul /command ^ | ||
| - | "open sftp://username:password@example.com/" ^ | + | "open sftp://user:password@example.com/" ^ |
| "put d:\examplefile.txt" ^ | "put d:\examplefile.txt" ^ | ||
| "exit" | "exit" | ||
| Line 41: | Line 41: | ||
| ===== [[newline_escaping]] New-line Escaping ===== | ===== [[newline_escaping]] New-line Escaping ===== | ||
| - | Many examples on this site (including the one above), as well as [[ui_generateurl#script|batch file template]] generated by WinSCP, use [[wp>Batch_file#Escaped_characters_in_strings|new-line escaping]] using the caret symbol ''^'' to allow wrapping a long command line to multiple lines for a better readability: | + | Many examples on this site (including the one above), as well as [[ui_generateurl#script|batch file template]] generated by WinSCP, use [[wp>Batch_file#Escaped_characters_in_strings|new-line escaping]] using the caret symbol ''^'' to allow wrapping a long command line to multiple lines for better readability: |
| <code batch> | <code batch> | ||
| winscp.com /log=winscp.log /ini=nul /command ^ | winscp.com /log=winscp.log /ini=nul /command ^ | ||
| - | "open sftp://username:password@example.com/" ^ | + | "open sftp://user:password@example.com/" ^ |
| "get *" ^ | "get *" ^ | ||
| "exit" | "exit" | ||
| Line 52: | Line 52: | ||
| When reusing/modifying such script, users frequently find that WinSCP seemingly stops processing the commands in a middle or behaves strangely. | When reusing/modifying such script, users frequently find that WinSCP seemingly stops processing the commands in a middle or behaves strangely. | ||
| - | This is commonly caused by an improper syntax of the new-line escaping in the batch file (and as such is not WinSCP issue at all). For the new-line escaping to work as expected, the caret symbol ''^'' has to be the very last character on the line (no spaces after it) and the next line needs to be indented (at least one space at the front). | + | This is commonly caused by an improper syntax of the new-line escaping in the batch file (and as such is not WinSCP issue at all). For the new-line escaping to work as expected in the batch file, the caret symbol ''^'' has to be the very last character on the line (no spaces after it) and the next line needs to be indented (at least one space at the front). |
| ===== [[quotes]] Double Double-quotes ===== | ===== [[quotes]] Double Double-quotes ===== | ||
| Line 65: | Line 65: | ||
| You need to double the percent sign to escape it. | You need to double the percent sign to escape it. | ||
| - | For example in the following batch file, the username ''username@domain'' contains the ''@'' sign. As the ''@'' sign has a special meaning in the session URL, it needs to be encoded to ''%40''. But as ''%'' sign has a special meaning in the batch file, it needs to be escaped as ''%%'', resulting in final ''%%40''. | + | For example in the following batch file, the username ''user@domain'' contains the ''@'' sign. As the ''@'' sign has a special meaning in the session URL, it needs to be encoded to ''%40''. But as ''%'' sign has a special meaning in the batch file, it needs to be escaped as '';<nowiki>%%</nowiki>'', resulting in final '';<nowiki>%%40</nowiki>''. |
| <code batch> | <code batch> | ||
| winscp.com /log=winscp.log /ini=nul /command ^ | winscp.com /log=winscp.log /ini=nul /command ^ | ||
| - | "open sftp://username%%40domain:password@example.com/" ^ | + | "open sftp://user%%40domain:password@example.com/" ^ |
| "get *" ^ | "get *" ^ | ||
| "exit" | "exit" | ||
| </code> | </code> | ||
| + | |||
| + | You can avoid the problem by specifying the credentials using the [[scriptcommand_open#username|''-username'']] and [[scriptcommand_open#password|''-password'']] switches: | ||
| + | |||
| + | <code batch> | ||
| + | winscp.com /log=winscp.log /ini=nul /command ^ | ||
| + | "open sftp://example.com/ -username=user@domain -password=password" ^ | ||
| + | "get *" ^ | ||
| + | "exit" | ||
| + | </code> | ||
| + | |||