Question Download last modified file from FTP server

devdevil10

New member
Joined
Jul 12, 2014
Messages
1
Programming Experience
Beginner
Hello all,


I am a vb.net newbie and I am trying to write a code that when executed pulls the latest file on an FTP server (based on creation date). So far, I've been able to list all the files in the remote directory. I know this can be done using regular expressions but unfortunately, I have no idea of how to implement that inside a code. So, any help is appreciated.


Regular expression to get the oldest file which I found somewhere [but need one to get the newest file though :( ]

VB.NET:
(\d{2}-\d{2}-\d{2}\s{1,10}\d{2}:\d{2}\w{2})\s{1,21}(\d{1,10})\s{1,10}(.+)

My progress so far.

VB.NET:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


        Dim ftpRequest As FtpWebRequest = DirectCast(WebRequest.Create("ftp://ftp.sitename.com/logs"), FtpWebRequest)


        ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails


        ftpRequest.Credentials = New NetworkCredential("username", "password")


        Dim ftpResponse As FtpWebResponse = DirectCast(ftpRequest.GetResponse(), FtpWebResponse)


        Dim ftpResponseStream As Stream = ftpResponse.GetResponseStream()


        Dim ftpReader As New StreamReader(ftpResponseStream)


        Console.WriteLine(ftpReader.ReadToEnd())


        MsgBox("Directory List Complete...!")


        ftpReader.Close()
        ftpResponse.Close()


    End Sub
 
Back
Top