Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to copy a file from a pc to a server using impersonate (<username,password>).
When I wrote the follwing code and run it exception was thrown "logon failure unknown username or bad password".
Can anyone help?

C#
using (new Tools.Impersonator(Serv_UName, "",Serv_Pwd))
{
    if (File.Exists(DestFileName))
    {
        MessageBox.Show("already exists in destination");
        return 1;
    }
    else
    {
        File.Copy(Src_FileName, DestFileName, true);
        return 0;
    }
}
Posted
Updated 1-Jun-11 22:00pm
v2

 
Share this answer
 
v3
Comments
Reem Moh 2-Jun-11 4:11am    
wt's wrong in my code!!
Rob Branaghan 2-Jun-11 4:24am    
Did you have a look at that Article?
Reem Moh 2-Jun-11 4:32am    
ys, but i donnow where to place my code that copy file !!
Rob Branaghan 2-Jun-11 4:34am    
Try copy and pasting into a new class in your app. Add your applications namespace.
And then try it to see if it works.

Is the computer you are trying to talk to on a domain? because you dont appear to be sending a domain?
Reem Moh 2-Jun-11 4:49am    
no domain
The error message you are seeing is pretty clear - you haven't provided credentials that it can correctly authenticate with.

You say you are connecting to a server - so what account are you expecting to use to authenticate against the server? A domain account, or a local account on the server?

The arguments you are providing are

Serv_UName, "",Serv_Pwd


What is the middle argument? Is it 'domain'? If so, try the following

Serv_UName, Serv_Name, Serv_Pwd


So if I wanted to connect to a server called SERVER1 with account dmorley, it would read

using (new Tools.Impersonator("dmorley", "SERVER1", "S0mePa55word"))


You need to make sure that the account exists on the server you are connecting to
 
Share this answer
 
Comments
Reem Moh 2-Jun-11 4:44am    
no domain
Dylan Morley 2-Jun-11 4:46am    
So, a local account on the server?

In what context is the account you are using? Where is the account defined?
Reem Moh 2-Jun-11 4:48am    
wt u mean!!
Dylan Morley 2-Jun-11 4:55am    
Where is the account defined - It must exist somewhere! Where has the account been created?

If you don't understand this, it's not suprising that you're seeing a 'logon failure' message

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900