I have tried multiple different ways of transferring a file from a server to another different server which is on the same domain. No matter what I try I keep getting the incorrect username or bad password error, however when I try access the "\serverIP\c$" folder manually from the server I am able to access the folder correctly with the right username and password.
The first part of my code places the file from the local pc to the server where the application is hosted, and this works perfectly :
string path = Path.Combine(Server.MapPath("~/ACAD_Drawings"),
Path.GetFileName(file.FileName));
file.SaveAs(path);
However I then need to move this file from this server onto a different server which will be using the file, and my last attempt was carried out using the following code:
NetworkCredential myCred = new NetworkCredential("Username", "Password", "DomainName");
WebClient webclient = new WebClient();
webclient.Credentials = myCred;
string tempFileForStorage = path;
file.SaveAs(tempFileForStorage);
webclient.UploadFile("\\\\NewServerIP\\c$", "PUT", tempFileForStorage);
webclient.Dispose();
System.IO.File.Delete(tempFileForStorage);
With this code I keep getting the incorrect username and password when I am sure that they are correct. Would anyone know if I am doing anything wrong or missing any steps?