Find files on a remote server
- by Peter Kelly
I have a web-service that resides on serverA. The webservice will be responsible for finding files of a certain type in a virtual directory on serverB and then returning the full URL to the files.
I have the service working if the files are located on the same machine - this is straight-forward enough. My question is what is the best way to find all files of a certain type (say *.xml) in all directories below a known virtual directory on a remote server?
So for example, the webservice is on http://ServerA/service.asmx and the virtual directory is located at http://serverB/virtualdirectory
So in this code, obviously the DirectoryInfo will not take a path to the remote server - how do I access this so I can find the files it contains? How do I then get the full URL to a file found on that remote server?
DirectoryInfo updateDirectory = new DirectoryInfo(path);
FileInfo[] files =
updateDirectory.GetFiles("*.xml", SearchOption.AllDirectories);
foreach (FileInfo fileInfo in files)
{
// Get URL to the file
}
I cannot have the files and the service on the same server - IT decision that is out of my hands.
Thanks!