Topic "Session.SynchronizeDirectories code example in VBA\VB6?"

Author Message
Rock28
[View user's profile]

Joined: 2014-10-28
Posts: 2
Location: USA
First of all, thank you very much to the author of WinSCP for this amazing software!

I'm using VB6 on 32-bit WinXP. WinSCPnet.dll has been registered, is listed in Project > References, and is checked. WinSCP is installed, tested, and working fine as a standalone program. What I'm trying to do is implement the SynchronizeDirectories.Remote functionality of WinSCP into the code that I'm writing that updates and deletes frequently-changing groups of files from local to my server.

The following code is exactly what I need, except its in VB.NET and I've been trying without success to translate it to VB6:
http://winscp.net/eng/docs/library_session_synchronizedirectories#vbnet

I just don't understand VB.NET enough to be able to translate all the code in the example to VB6. Can someone please post a full translation?
Advertisements
thom321
[View user's profile]

Joined: 2014-10-28
Posts: 5
Using the examples from the documentation, this code works, although it needs more result/error checking since it currently only checks uploads.
I was testing using ftp but I kept the original Sftp code (as a reminder to add more flexibility to the code) and skip over it using Goto. Obviously remove/edit this based on your setup.

Keep in mind that Session.SynchronizeDirectories has more options and I am implicitly using the defaults when not specified.


Code for VBA:


Code:

Sub SyncExample()
 
    Dim mySession As New Session
   
    ' Enable custom error handling
    On Error Resume Next
       
    SynchronizeDirectoryTest mySession
   
    ' Query for errors
    If Err.Number <> 0 Then
        MsgBox "Error: " & Err.Description
 
        ' Clear the error
        Err.Clear
    End If
     
    ' Disconnect, clean up
    mySession.Dispose
     
    ' Restore default error handling
    On Error GoTo 0
   
End Sub

Private Sub SynchronizeDirectoryTest(ByRef mySession As Session)
 
    ' Setup session options
    Dim mySessionOptions As New SessionOptions
   
    Dim sLocalPath as string
    Dim sRemotePath as string
   
    sLocalPath = "C:\Temp"
    sRemotePath = "example.com/test"
   
    GoTo FTPlogin 'remove this if you want to use Sftp.
   
    With mySessionOptions
        .Protocol = Protocol_Sftp
        .HostName = "example.com"
        .UserName = "user"
        .Password = "mypassword"
        .SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
    End With
   
   
FTPlogin:

    With mySessionOptions
       .Protocol = Protocol_Ftp
       .HostName = "example.com"
       .UserName = "user"
       .Password = "password"
       
    End With
       
    ' Connect
    mySession.Open mySessionOptions
   
    Dim mySynchronizationResult As SynchronizationResult
       
    Set mySynchronizationResult = mySession.SynchronizeDirectories(SynchronizationMode.SynchronizationMode_Remote, sLocalPath, sRemotePath, False)
       
         
    ' Throw on any error
    mySynchronizationResult.check
     
    ' Display results
    Dim transfer As TransferEventArgs
   
    For Each transfer In mySynchronizationResult.Uploads
        MsgBox "Upload of " & transfer.FileName & " succeeded"
    Next
   
End Sub



Rock28 wrote:
First of all, thank you very much to the author of WinSCP for this amazing software!

I'm using VB6 on 32-bit WinXP. WinSCPnet.dll has been registered, is listed in Project > References, and is checked. WinSCP is installed, tested, and working fine as a standalone program. What I'm trying to do is implement the SynchronizeDirectories.Remote functionality of WinSCP into the code that I'm writing that updates and deletes frequently-changing groups of files from local to my server.

The following code is exactly what I need, except its in VB.NET and I've been trying without success to translate it to VB6:
http://winscp.net/eng/docs/library_session_synchronizedirectories#vbnet

I just don't understand VB.NET enough to be able to translate all the code in the example to VB6. Can someone please post a full translation?
Rock28
[View user's profile]

Joined: 2014-10-28
Posts: 2
Location: USA
thom321,

Thank you so much for the code! It works excellently with no errors! Much, much appreciated!

You rock!
thom321
[View user's profile]

Joined: 2014-10-28
Posts: 5
Glad to hear it is working.

Rock28 wrote:
thom321,

Thank you so much for the code! It works excellently with no errors! Much, much appreciated!

You rock!
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
@thom321 Thanks for your contribution.

@Rock28 See also http://winscp.net/eng/docs/library_vb
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License