VBA: Synchronize progress

Advertisement

Monk
Joined:
Posts:
4
Location:
Germany

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.

TY SO MUCH!!!

Reply with quote

Advertisement

Guest

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"?

Hhmmm

Reply with quote

Monk
Joined:
Posts:
4
Location:
Germany

Really?

Sorry for answering as a guest.

Well in the examples: https://winscp.net/eng/docs/library_session_synchronizedirectories there is always a progress included:

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.

Reply with quote

martin
Site Admin
martin avatar

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.

Reply with quote

Advertisement

Monk
Joined:
Posts:
4
Location:
Germany

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?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,441
Location:
Prague, Czechia

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:
https://winscp.net/tracker/1802
You can vote for it there.

Reply with quote

Monk
Joined:
Posts:
4
Location:
Germany

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!

Reply with quote

martin
Site Admin
martin avatar

Re: Compare - how to get the results?

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

Reply with quote

Advertisement

You can post new topics in this forum