Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


Re: Compare - how to get the results?

Please try to implement it on your own and ask about any problems you encounter.

Compare - how to get the results?

Great!!! That helps a lot.
Of course it would be even better if you added a handler or sth. which indicates the progress of the synchronizarion 😁

But please... Can you give a short example how to get the number of results and then, in a loop, do the according action? That would be awesome 😅👍🏻

TY for this brilliant COM-library!

Monk wrote:

Couldn't we enumerate the differences and then let the necessary action (delete/upload) do afterwards?

Well, you can indeed do that. And call GetFiles/PutFiles/RemoveFiles as needed.
I am considering adding a method to the ComparisonDifference that will do that automatically.

This feature has been added to the tracker:
You can vote for it there.

I've got another idea.

There is this "comparedirectories" method, which is basically the same as synchronizedirectories but without the deleting/uploading.
The result is somehow stored...
Couldn't we enumerate the differences and then let the necessary action (delete/upload) do afterwards?

I tried it but without success. Maybe s.o. has an example for comparedirectories?

Re: Really?

Depends on what you actually want.
The FileTransferred is indeed called even during a synchronization. But it gives you a progress of individual file transfers.
It won't give you any indication of a progress of the sychronization as a whole.


Sorry for answering as a guest.

Well in the examples: there is always a progress included:

Imports WinSCP

Friend Class Example
    Public Shared Function Main() As Integer
            ' Setup session options
            Dim sessionOptions As New SessionOptions
            With sessionOptions
                .Protocol = Protocol.Sftp
                .HostName = ""
                .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
                ' Synchronize files
                Dim synchronizationResult As SynchronizationResult
                synchronizationResult =
                        SynchronizationMode.Remote, "d:\www", "/home/martin/public_html", False)
                ' Throw on any error
            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)
            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
                    "Permissions of {0} set to {1}", e.Chmod.FileName, e.Chmod.FilePermissions)
                    "Setting permissions of {0} failed: {1}", e.Chmod.FileName, e.Chmod.Error)
            End If
            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
                    "Timestamp of {0} set to {1}", e.Touch.FileName, e.Touch.LastWriteTime)
                    "Setting timestamp of {0} failed: {1}", e.Touch.FileName, e.Touch.Error)
            End If
            ' This should never happen during "local to remote" synchronization
                "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.

Re: VBA: Synchronize progress

martin wrote:

Indeed, progress reporting for synchronization is not supported atm.

What a pity!!!
So there's absolutely no trick or sth.? The user just sees the "waiting cursor"?


Re: VBA: Synchronize progress

Indeed, progress reporting for synchronization is not supported atm.

An full VB.NET example for using Session.FileTransferProgress event is at its documentation page:
It's for Session.GetFiles. But there's no difference when using it with Session.PutFiles.

VBA: Synchronize progress

Hi folks,
I searched and searched, found some hints, but I am as far as before.
You are my last hope^^
I am trying to synchronize local and remote folders and want a progressbar to be updated on a userform.
So, I read in this forum (but a quite old thread), that it's not possible to demand any kinds of progress when using the synchronize-method? Is that true?
And if it is really only possible with getfile, is is not possible when uploading? And do you have an easy example how to store the progress in a variable?
I am so confused... Please don't just post the link of handling the filetransferprogress-event. I read that and really need an easy example to understand how it works, how to get a value in a variable.