Question How do I display an FTP directory file list in a grid?

Dan181920

Active member
Joined
Jun 28, 2011
Messages
27
Programming Experience
Beginner
Hello,

I am trying to program my application so that when a user goes to my 'FTP Out' page, the page loads with a list of the files on my FTP site.

I know I will have to get a onnection going with my FTP site but how do I actually go about getting the list of details to show on my form?

All help and advice will be greatly appreciated.

Thanks,

Dan
 
You can use FtpWebRequest and set Method property to WebRequestMethods.Ftp.ListDirectoryDetails. Then you need to parse out the response, there are basically two formats to this listing, the unix style and the windows style according to the OS the FTP server is running.
 
Hello JohnH,

Thank you for your post.

I understand using the WebRequestMethids.ftp.ListDirectoryDetails.

I dont quite understand what you mean by 'parse out the response'.

Would you mind explaining this a little more please?

Thanks,

Dan
 
The response is a string containing the details, so you have to extract name, size and date and such details from that string.
 
Hi,

I am now getting the following error message:

HttpException was unhandled by user code

I then see a list of the files in the FTP directory but at the end of the list it says " ' is not a valid virtual path.

This may be a simple thing but was wondering if you or anybody else could explain this to me at all please? It is pointing to the 'Response.WriteFile(ftpReader.ReadToEnd())' part of my script.

Thank you in advance for the help.

Dan
 
That is not an error that is related to the ftp request.
 
Hi John,

How do you mean?

Is it saying that the way I have declared my FTPWebRequest?

Sorry, but I am very new to this, so I need a bit more explanation.

Thank you.

Dan
 
The error relates to the Response.WriteFile usage, it has nothing to do with ftp.
 
Hi John,

Thank you, I changed my code and am now getting the directory contents appear on the screen.

One more question, is there any way to change it so that not only can I see the list of files on the screen, but I can ALSO select a file that I wish to download to my desktop at all?

If so, what would I need to add to enable this functionality?

Many thanks,

Dan
 
You would need to parse out the inforrmation and display it in some kind of list control, so that user can select one item. Best approach would probably to provide a ftp link to have user download the file directly, but if that is not possible you would similarily have to provide some kind of selection interface, download the selected file to server, then return it to user.
 
John,

Could you explaina bit more at all please?

It would be best to put some sort of list tool on to my form that has a link to the FTP site?

Like a RadioButtonList that has a connection to the FTP site?

Is that what you are saying?

Many thanks,

Dan
 
I was more thinking along the lines of hyperlinks, so the user can download the files directly from the ftp server, saving the web server the trouble of that.
 
John,

Thank you.

I put a hyperlink in, so when the user clicks on it, it takes them to the FTP directory page.

Thank you very much.

Dan
 
Back
Top