Accessing server files using vb.net

lilgirl

Member
Joined
Jun 21, 2003
Messages
24
Hi,

I have files stored on an http server. I want to click on a button in vb.net and have it list all the file names on the server directory. Is there a way to do this. The directory I want to access is: something like http://123.45/folder/

Thanks.
 
I dont know how to do this, but would be interested in how it would be done.

Could be handy:)
 
that depends on that http server
if this server offers directory listening then you can simple get the html code and parse it
if not then there is only a possibility in getting the html code of one of the pages and go to all links which belong to that server

generally said you have to parse a lot of things which isnt that difficult if you find some points which indicates a start and stop and so on

an example for directory listing would be:
http://www.apache.org/dist/

there you see folders and files
then you just have to go through each line and check the symbol before the name of the folder/file
a folder symbol indicates a folder and a all other symbols indicate a file

have fun :)
 
thanks for your reply.

what i tried to do was have vb.net look through the server files the same way it looks through files on my computer.

For example:
Code:
 Dim files() As String = IO.Directory.GetFiles("http://199.98.xx.xx:xxxx/beams/")

However, when I try to run this, it says URIs not supported.

Is there some other class or function that would allow me to do this?

Thanks.
 
i dont have any code for you, but here is another way of accomplishing this. ive done something similar.

if the remote server supports asp.net, php, or any server-side scripting, you could probably write a script which reads the directory and prints each file on a new line.

for example we will call this script: dir.aspx ... when called, it would look something like this:

file1.zip
file2.zip
someotherfile.zip

so then you can make your vb.net application read: http://123.45/folder/dir.aspx and build an array of files based on that text.

sorry i dont have code for you, just the logic.

i wrote a .net windos app which does this, but im using php on the remote server to print out the files in the directory.

hope this helps. good luck.
 
thanks for the idea, sde.

using php on the server side, would i also be able to edit and delete files on the server using my application because I will also need to do that.

Thanks.
 
i suppose you could send a variable to the script, like:

http://host/folder/dir.php?action=delete&file=a.txt

then you would use php to delete the file ( unlink(filename); ) the directory would have to be 777 to allow php to delete files though.

this code would be something like:
Code:
<?
if($action == "delete")
{
  unlink($file);
}
?>
im not sure what type of files, but once you have the file names, you could download or read the files, then you could edit them in your .net app, and overwrite them back up to the server.

you would need to make an upload method. the directory will already be 777 permissions, so that should cover you there.
 
oh i thought you want to get the files of a host which you dont own
i could write something like a directory listing in php for you if that is a problem..

so the parse way is only for hosts you dont have access
 
thanks...i will have to look for tutorials on php now i guess..if you have any quick helpful links or sample code, i would appreciate it.

thanks again!
 
PHP code

<?php
if ($handle = opendir(.)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file<br>";
}
}
closedir($handle);
}
?>

that is just a simple way to display all files :)
 
i am now wondering how i can display the files and directories on the server in the folder browser dialog box...anyone know if there is a way to do this?

thanks!
 
the folder browser dialog box is a component of visual studio 2003 that allows the user to select a directory in a dialog box..similar to the file dialog box..except it only shows directories. so what i want to do is display the directories on the ftp server in that dialog...

any ideas are appreciated.
 
ah i think i understand you, what about building your own one?
a treeview could be quite helpful here :)
 
Dont use the class. It is buggy and will crash your application if selected path length > 135 characters (very unpredicatable when it will crashed).
 
Back
Top