Currently working on a FTP client in vb.net using FTPwebrequest. I have successfully made it work, it's uploading and retrieving all files and displaying it in a Listview. My concern right now is to Sort/Arranged the items in remote directory showed in listview to display the newly added items first and so on.
I have already tried researching online but to no avail. Still looking rightnow.
here is the code for displaying the contents of the directory
Private Sub SampleProcedure1()
Try
'Create an FTP web request
Dim ftpwebrequest As FtpWebRequest = DirectCast(WebRequest.Create("ftp://" & settings.txtserveraddress.Text & "/" & settings.foldername.Text & "/"), FtpWebRequest)
'Set properties
With ftpwebrequest
'ftp server username and password
.Credentials = New NetworkCredential(settings.txtserverusername.Text, settings.txtserverpassword.Text)
'set the method to download
.Method = WebRequestMethods.Ftp.ListDirectory
'upload timeout to 100 seconds
.Timeout = "100000"
End With
Dim ftpwebres As FtpWebResponse = CType(ftpwebrequest.GetResponse(), FtpWebResponse)
Dim ftpstreamreader As StreamReader = New StreamReader(ftpwebres.GetResponseStream())
'clear list of files
ftpclient.lstfiles.Items.Clear()
'start loading files from an FTP server into list
While (ftpstreamreader.Peek() > -1)
ftpclient.lstfiles.Items.Add(ftpstreamreader.ReadLine())
End While
ftpstreamreader.Close()
ftpwebres.Close()
Catch ex As Exception
ftpclient.Cursor = Cursors.Default
ftpclient.NotifyIcon1.ShowBalloonTip(1000, "Test FTP Client", ex.Message, ToolTipIcon.Info)
End Try
End Sub
The Listview should display/sort first base on the newest added/uploaded item. right not it sorts backwards and sorts alphabetical.