Differences
This shows you the differences between the selected revisions of the page.
2014-04-23 | 2014-04-24 | ||
no summary (159.233.252.74) | removing finally, this example concentraces on use of WinSCP assembly, it does not aim to be perfectly robust (martin) | ||
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 | ||
- | mySessionOptions = New SessionOptions | + | Dim mySessionOptions As New SessionOptions |
With mySessionOptions | With mySessionOptions | ||
.Protocol = Protocol.Sftp | .Protocol = Protocol.Sftp | ||
Line 134: | Line 124: | ||
End With | End With | ||
- | mySession = New Session | + | Using mySession As Session = New Session |
- | Using mySession | + | |
' Connect | ' Connect | ||
mySession.Open(mySessionOptions) | mySession.Open(mySessionOptions) | ||
' Upload files | ' Upload files | ||
- | myTransferOptions = New TransferOptions | + | Dim myTransferOptions As New TransferOptions |
myTransferOptions.TransferMode = TransferMode.Binary | myTransferOptions.TransferMode = TransferMode.Binary | ||
+ | Dim transferResult As TransferOperationResult | ||
transferResult = mySession.PutFiles("d:\toupload\*", "/home/user/", False, myTransferOptions) | transferResult = mySession.PutFiles("d:\toupload\*", "/home/user/", False, myTransferOptions) | ||
Line 155: | Line 145: | ||
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 | ||