Differences

This shows you the differences between the selected revisions of the page.

2016-03-07 2016-03-07
simplifying JScript example (martin) simplifying VBScript example (martin)
Line 288: Line 288:
session.Open sessionOptions session.Open sessionOptions
-Dim today, stamp +' Download files 
-today = Date +Dim transferOptions 
-stamp = Year(today) +Set transferOptions = WScript.CreateObject("WinSCP.TransferOptions") 
-If Month(today) < 10 Then +transferOptions.TransferMode = TransferMode_Binary 
-    stamp = stamp & "0" +  
-End If +Dim transferResult 
-stamp = stamp & Month(today) +Set transferResult = session.GetFiles("/home/user/*", "d:\toupload\", False, transferOptions
-if Day(today) < 10 Then +  
-    stamp = stamp & "0" +' Throw on any error 
-End If +transferResult.Check 
-stamp = stamp & Day(today) +  
- +' Print results 
-Dim fileName, remotePath, localPath +Dim transfer 
-fileName = "export_" & stamp & ".txt" +For Each transfer In transferResult.Transfers 
-remotePath = "/home/user/sysbatch/" & fileName + ···WScript.Echo "Download of " &amp; transfer.FileName & " succeeded
-localPath = "d:\backup\" & fileName +Next
- +
-Dim fs +
-Set fs = WScript.CreateObject("Scripting.FileSystemObject") +
-         +
-' Manual "remote to local" synchronization. +
- +
-' You can achieve the same using: +
-' Dim transferOptions +
-' Set transferOptions = WScript.CreateObject("WinSCP.TransferOptions") +
-' transferOptions.FileMask = fileName +
-' session.SynchronizeDirectories( _ +
-'    SynchronizationMode_Local, localPath, remotePath, false, false, SynchronizationCriteria_Time, _ +
-'    transferOptions).Check +
- +
-Dim download, remoteWriteTime, localWriteTime +
- +
-If session.FileExists(remotePath) Then +
-    If Not fs.FileExists(localPath) Then +
-        WScript.Echo "File " & remotePath & " exists, local backup " & localPath & " does not" +
-        download = True +
-    Else +
-        remoteWriteTime = CDate(session.GetFileInfo(remotePath).LastWriteTime) +
-        localWriteTime = fs.GetFile(localPath).DateLastModified +
- +
-        If remoteWriteTime > localWriteTime Then +
-            WScript.Echo _ +
-················"File &quot; &amp; remotePath &amp; " as well as local backup " & localPath & " exist, " &amp; _ +
-················&quot;but remote file is newer (" &amp; remoteWriteTime &amp; ") than local backup (" & localWriteTime & ")" +
-           download = True +
-········Else +
-           WScript.Echo +
-               "File " & remotePath & " as well as local backup " & localPath & " exist, " & _ +
-················&quot;but remote file is not newer (" & remoteWriteTime & ") than " & _ +
-               "local backup local backup (" & localWriteTime & ")" +
-············download = False +
-········End If +
-····End If +
- +
-   If download Then +
-        ' Download the file and throw on any error +
-        session.GetFiles(remotePath, localPath).Check() +
- +
- ·······WScript.Echo "Download to backup done." +
-    End If +
-Else +
-    WScript.Echo &quot;File &quot; & remotePath & " does not exist yet+
-End If+
' Disconnect, clean up ' Disconnect, clean up

Last modified: by martin