I want to upload some files to a remote machine frequently.We have an ftp .But I cannot use FTP for uploading file as ftp is not available from remote server. I planned to write an application for that using FileWebResponse class. As a starting point I just tried to access that machine using program. But I am getting an error like the network path not found.
Expand|Select|Wrap|Line Numbers
- FileWebResponse response=null;
- try
- {
- Uri uri = new Uri("file://remotemachinename/sharedfolder/sample.txt");
- if (uri.Scheme == Uri.UriSchemeFile)
- {
- FileWebRequest request = (FileWebRequest)FileWebRequest.Create(uri);
- request.Credentials = new NetworkCredential ("username", "password", "domainname");
- response = (FileWebResponse )request.GetResponse(); //ERROR happens here
- StreamReader reader = new StreamReader(response.GetResponseStream());
- string tmp = reader.ReadToEnd();
- response.Close();
- }
- }
- catch(Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- finally
- {
- if (response != null)
- {
- response.Close();
- }
- }
Note: Remotemachine is not in my network. I am able to connect the remotemachine using mstsc with a username and password in the domain of remotemachine. I want to read a file in a shared folder in D drive of that machine.
Could anybody give me a hint ...?
Thanks in advance,
jaleel