Post a reply

Options
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)

Options

Topic review

bfuchs

Permission denied error

This worked, thank you!
martin

Re: Permission denied error

It definitely should not be "/Outbox/*". Remove the /*.
bfuchs

Permission denied error

Hi I'm getting an error permission denied on the following
Set transferResult = _
    mySession.SynchronizeDirectories( _
        SynchronizationMode.SynchronizationMode_Local, _
        "H:\FTP\", "/Outbox/*", 0, 0, _
        SynchronizationCriteria.SynchronizationCriteria_Time, _
        myTransferOptions)

Any idea how to fix that?
thom321

Glad to hear it is working.
Rock28

@thom321,

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

You rock!
thom321

Re: Session.SynchronizeDirectories code example in VBA\VB6?

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:
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

Session.SynchronizeDirectories code example in VBA\VB6?

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:
https://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?