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

Toormser

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
 
    Try
        ' Setup session options
        Dim objSessionOptions As New SessionOptions
        With objSessionOptions
            .Protocol = Protocol.Sftp
            .HostName = "example.com"
            .UserName = "user"
            .Password = "mypassword"
        End With
 
        Using objSession As New Session
            ' Connect
            objSession.Open(objSessionOptions)
 
            ' 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
            objTransferResult.Check()
 
            ' Print results
            For Each transfer In objTransferResult.Transfers
                Console.WriteLine("Upload of {0} succeeded", transfer.FileName)
            Next
        End Using
 
        Return 0
    Catch ex As Exception
        mobjFileWriter.FileWrite(ex.ToString)
        Return 1
    End Try
 
End Function


Thanks in advance for you support!