The user name or password is incorrect when connecting to remote server
pantonis opened this issue · 4 comments
I have a remote VPS. I created a local user on that VPS. When I am trying to connect I am getting
The user name or password is incorrect
. When I test the credentials though by opening windows explorer on my local pc and trying to connect to that shared folder ("\IPAddressOfTheVPS) it seems they are correct.
My code is the following:
var credentials = new UserCredentials("\IPAddressOfTheVPS", user, pass);
Impersonation.RunAsUser(credentials, LogonType.Network, () =>
{
});
What is a VPS? What code do you actually use within the action block?
At the end of the day, this limited to the functionality provided by the underlying LogonUser
API of the operating system, and the .NET WindowsIdentity.RunImpersonated
method. It has no special magic, and is not a general purpose login library.
Also, not sure what you're passing for the first parameter to the UserCredentials
constructor, but there is an overload that only takes a username and password.
@mj1856 VPS Virtual Private Server (VM)
var credentials = new UserCredentials(@"\\80.145.14.55", user, pass);
Impersonation.RunAsUser(credentials, LogonType.Network, () =>
{
DirectoryInfo directory = new DirectoryInfo(@"\\80.145.14.55\SharedFolder");
FileInfo[] files = directory.GetFiles();
});
Try omitting the domain parameter from the UserCredentials
constructor. If that doesn't work, try passing "."
instead.
I assume if you just try to access the network share specified using the explorer in Windows that you get challenged for login and it works using the same credentials you're passing here?
It still does not work using the LogonType.Network.
I changed it to LogonType.NewCredentials and now it works.