Differences

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

2012-01-04 2012-01-10
List => Collection (martin) toc + example (martin)
Line 23: Line 23:
| TimeoutException | Timeout waiting for ''winscp.com'' to respond. | | TimeoutException | Timeout waiting for ''winscp.com'' to respond. |
-~~NOTOC~~+===== Example ===== 
 +<code csharp> 
 +using System; 
 +using System.Collections.ObjectModel; 
 +using WinSCP; 
 + 
 +class Test 
 +
 +    static void Main() 
 +    { 
 +        try 
 +        { 
 +            // Setup session options 
 +            SessionOptions sessionOptions = new SessionOptions(); 
 +            sessionOptions.Protocol = Protocol.Sftp; 
 +            sessionOptions.HostName = "example.com"; 
 +            sessionOptions.UserName = "user"; 
 +            sessionOptions.Password = "mypassword"; 
 +            sessionOptions.SshHostKey = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"; 
 + 
 +            using (Session session = new Session()) 
 +            { 
 +                // Connect 
 +                session.Open(sessionOptions); 
 + 
 +                Collection<RemoteFileInfo> files = session.ListDirectory("/home/martin/public_html"); 
 + 
 +                foreach (RemoteFileInfo fileInfo in files) 
 +                { 
 +                    Console.WriteLine("{0} with size {1}, permissions {2} and last modification at {3}", 
 +                        fileInfo.Name, fileInfo.Length, fileInfo.FilePermissions, fileInfo.LastWriteTime); 
 +                } 
 +            } 
 +        } 
 +        catch (Exception e) 
 +        { 
 +            Console.WriteLine("Error: {0}", e); 
 +        } 
 +    } 
 +
 +</code>

Last modified: by martin