Differences
This shows you the differences between the selected revisions of the page.
| 2013-10-08 | 2013-10-08 | ||
| no summary (83.160.137.23) (hidden) | no summary (83.160.137.23) (hidden) | ||
| Line 50: | Line 50: | ||
| Event ''[[library_session_filetransferred|Session.FileTransferred]]'' is raised for every uploaded or downloaded file. | Event ''[[library_session_filetransferred|Session.FileTransferred]]'' is raised for every uploaded or downloaded file. | ||
| - | ===== [[] Examples ===== | ||
| - | ==== [[csharp]] C# Example ==== | ||
| - | <code csharp> | ||
| - | using System; | ||
| - | using WinSCP; | ||
| - | class Example | ||
| - | { | ||
| - | public static int Main() | ||
| - | { | ||
| - | try | ||
| - | { | ||
| - | // Setup session options | ||
| - | SessionOptions sessionOptions = new SessionOptions { | ||
| - | Protocol = Protocol.Sftp, | ||
| - | HostName = "", | ||
| - | UserName = "", | ||
| - | Password = "", | ||
| - | SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | ||
| - | }; | ||
| - | |||
| - | using (Session session = new Session()) | ||
| - | { | ||
| - | // Will continuously report progress of synchronization | ||
| - | session.FileTransferred += FileTransferred; | ||
| - | |||
| - | // Connect | ||
| - | session.Open(sessionOptions); | ||
| - | |||
| - | // Synchronize files | ||
| - | SynchronizationResult synchronizationResult; | ||
| - | synchronizationResult = | ||
| - | session.SynchronizeDirectories( | ||
| - | SynchronizationMode.Remote, @"d:\www", "/home/martin/public_html", false); | ||
| - | |||
| - | // Throw on any error | ||
| - | synchronizationResult.Check(); | ||
| - | } | ||
| - | |||
| - | return 0; | ||
| - | } | ||
| - | catch (Exception e) | ||
| - | { | ||
| - | Console.WriteLine("Error: {0}", e); | ||
| - | return 1; | ||
| - | } | ||
| - | } | ||
| - | |||
| - | private static void FileTransferred(object sender, TransferEventArgs e) | ||
| - | { | ||
| - | if (e.Error == null) | ||
| - | { | ||
| - | Console.WriteLine("Upload of {0} succeeded", e.FileName); | ||
| - | } | ||
| - | else | ||
| - | { | ||
| - | Console.WriteLine("Upload of {0} failed: {1}", e.FileName, e.Error); | ||
| - | } | ||
| - | |||
| - | if (e.Chmod != null) | ||
| - | { | ||
| - | if (e.Chmod.Error == null) | ||
| - | { | ||
| - | Console.WriteLine("Permisions of {0} set to {1}", e.Chmod.FileName, e.Chmod.FilePermissions); | ||
| - | } | ||
| - | else | ||
| - | { | ||
| - | Console.WriteLine("Setting permissions of {0} failed: {1}", e.Chmod.FileName, e.Chmod.Error); | ||
| - | } | ||
| - | } | ||
| - | else | ||
| - | { | ||
| - | Console.WriteLine("Permissions of {0} kept with their defaults", e.Destination); | ||
| - | } | ||
| - | |||
| - | if (e.Touch != null) | ||
| - | { | ||
| - | if (e.Touch.Error == null) | ||
| - | { | ||
| - | Console.WriteLine("Timestamp of {0} set to {1}", e.Touch.FileName, e.Touch.LastWriteTime); | ||
| - | } | ||
| - | else | ||
| - | { | ||
| - | Console.WriteLine("Setting timestamp of {0} failed: {1}", e.Touch.FileName, e.Touch.Error); | ||
| - | } | ||
| - | } | ||
| - | else | ||
| - | { | ||
| - | // This should never happen with Session.SynchronizeDirectories | ||
| - | Console.WriteLine("Timestamp of {0} kept with its default (current time)", e.Destination); | ||
| - | } | ||
| - | } | ||
| - | } | ||
| - | </code> | ||
| ==== [[vbnet]] VB.NET Example ==== | ==== [[vbnet]] VB.NET Example ==== | ||