Differences

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

2012-03-09 2012-03-09
using object initializer c# (martin) vb.net example (martin)
Line 24: Line 24:
===== Example ===== ===== Example =====
 +==== [[csharp]] C# Example ====
<code csharp> <code csharp>
using System; using System;
Line 67: Line 68:
} }
</code> </code>
 +
 +==== [[vbnet]] VB.NET Example ====
 +<code vbnet>
 +Imports System
 +Imports WinSCP
 +
 +Friend Class Example
 +
 +    Public Shared Function Main() As Integer
 +
 +        Try
 +            ' Setup session options
 +            Dim sessionOptions As New SessionOptions { _
 +                .Protocol = Protocol.Sftp, _
 +                .HostName = "example.com", _
 +                .UserName = "user", _
 +                .Password = "mypassword", _
 +                .SshHostKey = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" _
 +            }
 +
 +            Using session As Session = New Session
 +                ' Connect
 +                session.Open(sessionOptions)
 +
 +                Dim directory As RemoteDirectoryInfo = session.ListDirectory("/home/martin/public_html")
 +
 +                Dim fileInfo As RemoteFileInfo
 +                For Each fileInfo In directory.Files
 +                    Console.WriteLine("{0} with size {1}, permissions {2} and last modification at {3}", _
 +                        fileInfo.Name, fileInfo.Length, fileInfo.FilePermissions, fileInfo.LastWriteTime)
 +                Next
 +            End Using
 +
 +            Return 0
 +        Catch e As Exception
 +            Console.WriteLine("Error: {0}", e)
 +            Return 1
 +        End Try
 +
 +    End Function
 +
 +End Class
 +</code>
 +
 +

Last modified: by martin