List control to view list of files on FTP site
Hello,
I am attempting to put a list box in to my program, so that when the page loads, a list of files from my FTP site appear.
I also want it so that a file can be selected on the screen and downloaded.
Is there a way to do this?
If so, what sort of listbox should I be looking at? Because the only ones I have come across only connect to Access or SQL Server databases.
Please help...
Thanks,
Dan
dwinn
Junior Poster in Training
53 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
Thank you for your message stbuchok.
Ive now got it so the list of FTP files are appearing on the screen and I am now able to select a file from the list and download it.
The problem I have now is that when I load the page, instead of each file only appearing in the list once, each file appears multiple times.
Below is the code that I am using:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim ftp As FtpWebRequest = DirectCast(WebRequest.Create("ftp://xx.x.xx.xx/In/"), FtpWebRequest)
ftp.Method = WebRequestMethods.Ftp.ListDirectory
Dim ftpFiles As New ArrayList()
ftp.Credentials = New NetworkCredential("user", "password")
Dim Response As FtpWebResponse = ftp.GetResponse()
Dim responseStream As Stream = Response.GetResponseStream()
Dim reader = New StreamReader(responseStream)
While Not (reader.EndOfStream)
ftpFiles.Add(reader.ReadLine())
'ListBox1.Items.Add(ftpFiles.ToString())
For Each file In ftpFiles
ListBox1.Items.Add(file)
Next
End While
reader.Close()
responseStream.Close()
Response.Close()
End Sub
I want it so that each file only appears once in the list.
All help and advice will be greatly appreciated.
Thanks,
Dan
dwinn
Junior Poster in Training
53 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
Hi stbuchok,
Thank you very much!!!
It works perfectly.
Much appreciated.
Dan
dwinn
Junior Poster in Training
53 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0