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

ltamerica

Re: Download latest file from SFTP server using VB.net

Thanks! got it to work with the snippet you provided.
ltamerica

Download latest file from SFTP server using VB.NET

Hi all,

I'm a bit new to using SFTP assembly AND vb.net. I've managed to setup the connection and download all files to my local folder via session.GetFiles. I understand this will just get everything what's in the folder.

What I'm struggling with is to only get the latest file from the folder, I've checked the examples found on this site, but they don't give me the vb.net syntax i would need.

my current simplified sample code:
Try
    Using session As New Session
       session.open(sessionOptions)
 
        Dim SourceFolder As String = session.HomePath & "/Test/"
        Dim TargetFolder As String = "C:\Test\"
 
        Dim transferOptions As New TransferOptions
        transferOptions.TransferMode = TransferMode.Binary
 
        Dim transferResult As TransferOperationResult
        transferResult =session.GetFiles(SourceFolder, TargetFolder, False, transferOptions)
        transferResult.Check()
 
        For Each transfer In transferResult.Transfers
            Console.WriteLine("Download of {0} succeeded", transfer.FileName)
 
        Next
    End Using
    Return 0
Catch e As Exception
    Console.WriteLine("Error: {0}", e)
    Return 1
End Try

who can help me in the right direction?

kr,
LT