Permission denied error
This worked, thank you!
"/Outbox/*"
. Remove the /*
.
Set transferResult = _
mySession.SynchronizeDirectories( _
SynchronizationMode.SynchronizationMode_Local, _
"H:\FTP\", "/Outbox/*", 0, 0, _
SynchronizationCriteria.SynchronizationCriteria_Time, _
myTransferOptions)
Goto
. Obviously remove/edit this based on your setup.
Session.SynchronizeDirectories
has more options and I am implicitly using the defaults when not specified.
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
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.