Hi, I'm trying to figure out how to list all files of an FTP folder in a listview but I can't figure out how to do this. I tried using the same approach as if I were to list contents of a folder in my harddrive. But this fails.
Any ideas?
I thought of something like this (in vb.net, but I'm sure c# is pretty similar):
Public Sub FTPFill()
Dim ftpreq As FtpWebRequest = FtpWebRequest.Create("ftp://FTPRoot/")
With ftpreq
.Credentials = New NetworkCredential(My.Settings.FTPUsername, My.Settings.FTPPassword)
.Method = WebRequestMethods.Ftp.ListDirectory
End With
Dim sr As New StreamReader(ftpreq.GetResponse().GetResponseStream())
Dim str As String = sr.ReadLine()
For Each str In sr.ReadLine()
Dim lvi As New ListViewItem(sr.ReadLine())
lvi.ImageIndex = 0
lvi.SubItems.Add("Folder")
lvi.SubItems.Add(Path.GetExtension((sr.ReadLine())))
ListView.Items.Add(lvi)
Next
End Sub
But I'm not sure what I'm doing during the "For Each" loop.