Sorry for answering as a guest.
Imports WinSCP
Friend Class Example
Public Shared Function Main() As Integer
Try
' Setup session options
Dim sessionOptions As New SessionOptions
With sessionOptions
.Protocol = Protocol.Sftp
.HostName = "example.com"
.UserName = "user"
.Password = "mypassword"
.SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...="
End With
Using session As New Session
' Will continuously report progress of synchronization
AddHandler session.FileTransferred, AddressOf FileTransferred
' Connect
session.Open(sessionOptions)
' Synchronize files
Dim synchronizationResult As SynchronizationResult
synchronizationResult =
session.SynchronizeDirectories(
SynchronizationMode.Remote, "d:\www", "/home/martin/public_html", False)
' Throw on any error
synchronizationResult.Check()
End Using
Return 0
Catch e As Exception
Console.WriteLine("Error: {0}", e)
Return 1
End Try
End Function
Private Shared Sub FileTransferred(sender As Object, e As TransferEventArgs)
If e.Error Is Nothing Then
Console.WriteLine("Upload of {0} succeeded", e.FileName)
Else
Console.WriteLine("Upload of {0} failed: {1}", e.FileName, e.Error)
End If
If e.Chmod IsNot Nothing Then
If e.Chmod.Error Is Nothing Then
Console.WriteLine(
"Permissions 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)
End If
Else
Console.WriteLine("Permissions of {0} kept with their defaults", e.Destination)
End If
If e.Touch IsNot Nothing Then
If e.Touch.Error Is Nothing Then
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)
End If
Else
' This should never happen during "local to remote" synchronization
Console.WriteLine(
"Timestamp of {0} kept with its default (current time)", e.Destination)
End If
End Sub
End Class
That's not working - or sth. different? Please help^^ By the way, I tried to translate it into VBA, but didn't get far. AddHandler e.g. is a problem.