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


Delete remote Files if these local no more exists

Hello Community,

Is there a way in vbnet Assembly to delete remote files if there are no more available on local storage. My intenation about this is:

1. File Upload (only newer files reg. the FileMask)
2. Check if remote-files are there which are not there on local storage (old files)
3. Delete remote-files, which are not available on local storage

Is there a way for point 2 & 3? You can see my code below.

Public Function UploadBackupToOnlineStorage() As Boolean
        ' Setup session options
        Dim objSessionOptions As New SessionOptions
        With objSessionOptions
            .Protocol = Protocol.Sftp
            .HostName = ""
            .UserName = "user"
            .Password = "mypassword"
        End With
        Using objSession As New Session
            ' Connect
            ' Upload files
            Dim objTransferOptions As New TransferOptions
            objTransferOptions.TransferMode = TransferMode.Binary
            objTransferOptions.FileMask = "*>=1D"
            Dim objTransferResult As TransferOperationResult
            objTransferResult =
                objSession.PutFiles("D:\*", "/", False, objTransferOptions)
            ' Throw on any error
            ' Print results
            For Each transfer In objTransferResult.Transfers
                Console.WriteLine("Upload of {0} succeeded", transfer.FileName)
        End Using
        Return 0
    Catch ex As Exception
        Return 1
    End Try
End Function

Thanks in advance for you support!