Differences
This shows you the differences between the selected revisions of the page.
2014-03-07 | 2014-04-23 | ||
old revision restored (martin) | no summary (159.233.252.74) | ||
Line 113: | Line 113: | ||
Public Shared Function Main() As Integer | Public Shared Function Main() As Integer | ||
+ | 'JRS Apr 23 2014 (joe@astutedata.com) | ||
+ | ' Changed variable names because VB is NOT case sensitive. | ||
+ | ' Incorporated Finally clause | ||
+ | |||
+ | Dim mySessionOptions As SessionOptions = Nothing | ||
+ | Dim mySession As Session = Nothing | ||
+ | Dim myTransferOptions As TransferOptions = Nothing | ||
+ | Dim transferResult As TransferOperationResult = Nothing | ||
+ | Dim transfer As TransferEventArgs = Nothing | ||
Try | Try | ||
' Setup session options | ' Setup session options | ||
- | Dim sessionOptions As New SessionOptions | + | mySessionOptions = New SessionOptions |
- | With sessionOptions | + | With mySessionOptions |
.Protocol = Protocol.Sftp | .Protocol = Protocol.Sftp | ||
.HostName = "example.com" | .HostName = "example.com" | ||
Line 125: | Line 134: | ||
End With | End With | ||
- | Using session As Session = New Session | + | mySession = New Session |
+ | Using mySession | ||
' Connect | ' Connect | ||
- | session.Open(sessionOptions) | + | mySession.Open(mySessionOptions) |
' Upload files | ' Upload files | ||
- | Dim transferOptions As New TransferOptions | + | myTransferOptions = New TransferOptions |
- | transferOptions.TransferMode = TransferMode.Binary | + | myTransferOptions.TransferMode = TransferMode.Binary |
- | Dim transferResult As TransferOperationResult | + | transferResult = mySession.PutFiles("d:\toupload\*", "/home/user/", False, myTransferOptions) |
- | ················transferResult = session.PutFiles("d:\toupload\*", "/home/user/", False, transferOptions) | + | |
' Throw on any error | ' Throw on any error | ||
- | transferResult.Check | + | transferResult.Check() |
' Print results | ' Print results | ||
- | Dim transfer As TransferEventArgs | ||
For Each transfer In transferResult.Transfers | For Each transfer In transferResult.Transfers | ||
Console.WriteLine("Upload of {0} succeeded", transfer.FileName) | Console.WriteLine("Upload of {0} succeeded", transfer.FileName) | ||
Line 147: | Line 155: | ||
Return 0 | Return 0 | ||
+ | |||
Catch e As Exception | Catch e As Exception | ||
+ | |||
Console.WriteLine("Error: {0}", e) | Console.WriteLine("Error: {0}", e) | ||
Return 1 | Return 1 | ||
+ | |||
+ | Finally | ||
+ | |||
+ | transfer = Nothing | ||
+ | transferResult = Nothing | ||
+ | myTransferOptions = Nothing | ||
+ | mySession = Nothing | ||
+ | mySessionOptions = Nothing | ||
+ | |||
End Try | End Try | ||