Differences
This shows you the differences between the selected revisions of the page.
| 2014-06-12 | 2014-07-21 | ||
| using Add-Type cmdlet instead of Assembly.LoadFrom method (martin) | timestamp formating in a batch file (martin) | ||
| Line 106: | Line 106: | ||
| ==== Using WinSCP Scripting ==== | ==== Using WinSCP Scripting ==== | ||
| + | === From a Batch File === | ||
| + | In Windows batch file, you may retrieve current time in locale-independent format using command ''[[http://technet.microsoft.com/en-us/library/bb491034.aspx|wmic]] os get LocalDateTime''. You can parse the value using using [[http://en.wikibooks.org/wiki/Windows_Batch_Scripting#String_processing|string processing syntax]]: | ||
| + | |||
| + | <code> | ||
| + | @echo off | ||
| + | |||
| + | for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set LDT=%%j | ||
| + | set STAMP=%LDT:~0,4%%LDT:~4,2%%LDT:~6,2%%LDT:~8,2%%LDT:~10,2%%LDT:~12,2% | ||
| + | |||
| + | winscp.com /script=script.txt | ||
| + | </code> | ||
| + | |||
| + | //Note that the expression after ''set STAMP='' shows how to extract individual date/time components, in case you need to interleave them by some punctuation. If not, you can replace it by simple ''%LDT:~0,14%''.// | ||
| + | |||
| + | The ''script.txt'' should make use of the variable ''STAMP'' using ''%STAMP%'' [[scripting#syntax|syntax]]. For example: | ||
| + | |||
| + | <code winscp> | ||
| + | option batch abort | ||
| + | option confirm off | ||
| + | open session | ||
| + | get "/home/user/download.txt" "C:\downloaded\download.txt.%STAMP%" | ||
| + | exit | ||
| + | </code> | ||
| + | |||
| + | === From a JavaScript === | ||
| You may use following [[guide_automation_advanced#wsh|Windows script host JavaScript code]] (''example.js''): | You may use following [[guide_automation_advanced#wsh|Windows script host JavaScript code]] (''example.js''): | ||