Differences
This shows you the differences between the selected revisions of the page.
guide_ftp_script_to_sftp 2018-04-24 | guide_ftp_script_to_sftp 2022-10-21 (current) | ||
Line 1: | Line 1: | ||
====== Converting Windows FTP script to WinSCP SFTP script ====== | ====== Converting Windows FTP script to WinSCP SFTP script ====== | ||
- | This guide explains how to convert existing FTP file transfer script using [[https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/ftp|Windows built-in command-line FTP client]] (''ftp.exe'') to SFTP [[scripting|script using WinSCP]]. | + | This guide explains how to convert existing FTP file transfer script using [[https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/ftp|Windows built-in command-line FTP client]] (''ftp.exe'') to SFTP [[scripting|script using WinSCP]]. |
- | You can also use it to convert FTP script using ''ftp.exe'' to WinSCP, in case you want to use some advanced feature that WinSCP offers, such as [[ftps|FTP over TLS/SSL]], [[scriptcommand_synchronize|synchronization]], passive mode((WinSCP defaults to passive mode.)), [[script_upload_multiple_servers|parametrized script]], [[scripting#timestamp|timestamped file names]], [[script_custom_listing_format_csv|custom directory listing format]], UTF-8 support, preserving file timestamp, recursive downloads and uploads, and others. | + | You can also use it to convert FTP script using ''ftp.exe'' to WinSCP, in case you want to use some advanced feature that WinSCP offers, such as [[ftps|FTP over TLS/SSL]], [[scriptcommand_synchronize|synchronization]], passive mode,((WinSCP defaults to passive mode.)) [[script_upload_multiple_servers|parametrized script]], [[scripting#timestamp|timestamped file names]], [[script_custom_listing_format_csv|custom directory listing format]], UTF-8 support, preserving file timestamp, recursive downloads and uploads, and others. |
===== [[commandline]] Converting Command-Line ===== | ===== [[commandline]] Converting Command-Line ===== | ||
Line 59: | Line 59: | ||
Replace the ''%%sftp://%%'' with the ''%%ftp://%%'', if you keep using the FTP protocol. | Replace the ''%%sftp://%%'' with the ''%%ftp://%%'', if you keep using the FTP protocol. | ||
+ | |||
+ | ===== [[errors]] Error Handling ===== | ||
+ | WinSCP by default aborts the script when some of the commands fail. On the contrary ''ftp.exe'' continues processing a script after an error. If your original ''ftp.exe'' script relies on this behavior, you can emulate it in WinSCP by switching the [[scriptcommand_option#batch|batch mode]] to ''on'' at the beginning of your script: | ||
+ | <code winscp> | ||
+ | option batch on | ||
+ | </code> | ||
===== Converting Commands ===== | ===== Converting Commands ===== | ||
+ | |||
==== [[append]] append ==== | ==== [[append]] append ==== | ||
Use ''[[scriptcommand_put|put]] -append <localfile> [remotefile]''. | Use ''[[scriptcommand_put|put]] -append <localfile> [remotefile]''. | ||
Line 107: | Line 114: | ||
Note that WinSCP also supports ''binary'' command, but its use is deprecated. | Note that WinSCP also supports ''binary'' command, but its use is deprecated. | ||
- | ==== cd ==== | + | ==== [[cd]] cd ==== |
Use ''[[scriptcommand_cd|cd]]'' command. | Use ''[[scriptcommand_cd|cd]]'' command. | ||
- | ==== close ==== | + | ==== [[close]] close ==== |
Use ''[[scriptcommand_close|close]]'' command. | Use ''[[scriptcommand_close|close]]'' command. | ||
- | ==== delete ==== | + | ==== [[delete]] delete ==== |
Use ''[[scriptcommand_rm|rm]]'' command. | Use ''[[scriptcommand_rm|rm]]'' command. | ||
Note that WinSCP also supports ''delete'' alias. | Note that WinSCP also supports ''delete'' alias. | ||
- | ==== dir ==== | + | ==== [[dir]] dir ==== |
Use ''[[scriptcommand_ls|ls]]'' command. | Use ''[[scriptcommand_ls|ls]]'' command. | ||
Line 125: | Line 132: | ||
Note that WinSCP also supports ''dir'' alias. | Note that WinSCP also supports ''dir'' alias. | ||
- | ==== disconnect ==== | + | ==== [[disconnect]] disconnect ==== |
Alias to ''[[scriptcommand_close|close]]'' command. | Alias to ''[[scriptcommand_close|close]]'' command. | ||
Line 146: | Line 153: | ||
</code> | </code> | ||
- | ==== glob ==== | + | ==== [[glob]] glob ==== |
In WinSCP, to escape special characters in filename, use [[file_mask#basic|set pattern]]. | In WinSCP, to escape special characters in filename, use [[file_mask#basic|set pattern]]. | ||
For example to download file with literal ''*'' character, use ''get filewithstar[*]''. | For example to download file with literal ''*'' character, use ''get filewithstar[*]''. | ||
- | ==== hash ==== | + | ==== [[hash]] hash ==== |
WinSCP always prints percentual progress of file transfer when run in console. It does not output progress when redirected to a file. | WinSCP always prints percentual progress of file transfer when run in console. It does not output progress when redirected to a file. | ||
- | ==== lcd ==== | + | ==== [[lcd]] lcd ==== |
Use ''[[scriptcommand_lcd|lcd]]'' command. | Use ''[[scriptcommand_lcd|lcd]]'' command. | ||
Line 162: | Line 169: | ||
With FTP protocol, you can use ''call'' command to execute FTP protocol commands. | With FTP protocol, you can use ''call'' command to execute FTP protocol commands. | ||
- | ==== ls ==== | + | ==== [[ls]] ls ==== |
You can use ''[[scriptcommand_ls|ls]]'' command to list directory contents with full details. | You can use ''[[scriptcommand_ls|ls]]'' command to list directory contents with full details. | ||
- | ==== mdelete ==== | + | ==== [[mdelete]] mdelete ==== |
Use ''[[scriptcommand_rm|rm]]'' command. | Use ''[[scriptcommand_rm|rm]]'' command. | ||
- | ==== mget ==== | + | ==== [[mget]] mget ==== |
Use ''[[scriptcommand_get|get]]'' command. | Use ''[[scriptcommand_get|get]]'' command. | ||
Line 192: | Line 199: | ||
Note that WinSCP also supports ''mget'' as an alias to ''get'' command. | Note that WinSCP also supports ''mget'' as an alias to ''get'' command. | ||
- | ==== mkdir ==== | + | ==== [[mkdir]] mkdir ==== |
Use ''[[scriptcommand_mkdir|mkdir]]'' command. | Use ''[[scriptcommand_mkdir|mkdir]]'' command. | ||
- | ==== mput ==== | + | ==== [[mput]] mput ==== |
- | Use ''[[scriptcommand_get|put]]'' command. | + | Use ''[[scriptcommand_put|put]]'' command. |
You need to map previous ''[[#binary|binary]]'' or ''[[#ascii|ascii]]'' commands to ''-transfer'' switch. | You need to map previous ''[[#binary|binary]]'' or ''[[#ascii|ascii]]'' commands to ''-transfer'' switch. | ||
Line 219: | Line 226: | ||
Note that WinSCP also supports ''mput'' as an alias to ''put'' command. | Note that WinSCP also supports ''mput'' as an alias to ''put'' command. | ||
- | ==== open ==== | + | ==== [[open]] open ==== |
Use ''[[scriptcommand_open|open]]'' command. | Use ''[[scriptcommand_open|open]]'' command. | ||
Line 248: | Line 255: | ||
Replace the ''%%sftp://%%'' with the ''%%ftp://%%'', if you keep using the FTP protocol. | Replace the ''%%sftp://%%'' with the ''%%ftp://%%'', if you keep using the FTP protocol. | ||
- | ==== prompt ==== | + | ==== [[prompt]] prompt ==== |
WinSCP does not prompt for individual transfers during multi-file transfers, so there's no conversion needed. | WinSCP does not prompt for individual transfers during multi-file transfers, so there's no conversion needed. | ||
Line 270: | Line 277: | ||
</code> | </code> | ||
- | ==== pwd ==== | + | ==== [[pwd]] pwd ==== |
Use ''[[scriptcommand_pwd|pwd]]'' command. | Use ''[[scriptcommand_pwd|pwd]]'' command. | ||
- | ==== quit ==== | + | ==== [[quit]] quit ==== |
Alias to ''[[#bye|bye]]'' command. | Alias to ''[[#bye|bye]]'' command. | ||
Line 279: | Line 286: | ||
Alias to ''[[#literal|literal]]'' command. | Alias to ''[[#literal|literal]]'' command. | ||
- | ==== recv ==== | + | ==== [[recv]] recv ==== |
Alias to ''[[#get|get]]'' command. | Alias to ''[[#get|get]]'' command. | ||
Note that WinSCP also supports ''recv'' alias. | Note that WinSCP also supports ''recv'' alias. | ||
- | ==== rename ==== | + | ==== [[rename]] rename ==== |
Use ''[[scriptcommand_mv|mv]]'' command. | Use ''[[scriptcommand_mv|mv]]'' command. | ||
Note that WinSCP also supports ''rename'' alias. | Note that WinSCP also supports ''rename'' alias. | ||
- | ==== rmdir ==== | + | ==== [[rmdir]] rmdir ==== |
Use ''[[scriptcommand_rmdir|rmdir]]'' command. | Use ''[[scriptcommand_rmdir|rmdir]]'' command. | ||
- | ==== send ==== | + | ==== [[send]] send ==== |
Alias to ''[[#put|put]]'' command. | Alias to ''[[#put|put]]'' command. | ||
Note that WinSCP also supports ''send'' alias. | Note that WinSCP also supports ''send'' alias. | ||
- | ==== type ==== | + | ==== [[type]] type ==== |
Command ''type ascii'' is an alias to ''[[#ascii|ascii]]'' command. | Command ''type ascii'' is an alias to ''[[#ascii|ascii]]'' command. | ||
Line 321: | Line 328: | ||
Replace the ''%%sftp://%%'' with the ''%%ftp://%%'', if you keep using the FTP protocol. | Replace the ''%%sftp://%%'' with the ''%%ftp://%%'', if you keep using the FTP protocol. | ||
- | ==== verbose ==== | + | ==== [[verbose]] verbose ==== |
There is no direct equivalent. | There is no direct equivalent. | ||