By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,015 Members | 998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,015 IT Pros & Developers. It's quick & easy.

Copy a file from 1 domain to another

P: n/a
Hello,

I am trying to copy a file from one domain to another. I have the username
and password of the destination domain. I tried a few approaches -
1. Using the Impersonator Class -
http://www.codeproject.com/useritems...personator.asp

2. Using WebRequest object to write the file to the destination domain -
http://www.dotnet247.com/247referenc...42/211482.aspx

3.
http://www.codebetter.com/blogs/bren.../24/26730.aspx
Mapping to a network drive will not work in this scenario because of design
requirements.

The 1st 2 approaches gave me the same error - Access denied to MyFile.txt.
This is a console application and the 2 domains I am referring to are on the
same internal network and not across the internet.

Could someone please give me a pointer to solve this problem? Any help with
this will be appreciated!

Thanks,
-Divya
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
When using 2, did you get an access denied reading the file or creating the
file?

Gabriel Lozano-Morán

"Divya" <Di***@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
Hello,

I am trying to copy a file from one domain to another. I have the username
and password of the destination domain. I tried a few approaches -
1. Using the Impersonator Class -
http://www.codeproject.com/useritems...personator.asp

2. Using WebRequest object to write the file to the destination domain -
http://www.dotnet247.com/247referenc...42/211482.aspx

3.
http://www.codebetter.com/blogs/bren...09/24/26730.as
px Mapping to a network drive will not work in this scenario because of design requirements.

The 1st 2 approaches gave me the same error - Access denied to MyFile.txt.
This is a console application and the 2 domains I am referring to are on the same internal network and not across the internet.

Could someone please give me a pointer to solve this problem? Any help with this will be appreciated!

Thanks,
-Divya

Nov 17 '05 #2

P: n/a

"Divya" <Di***@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
Hello,

I am trying to copy a file from one domain to another. I have the username
and password of the destination domain. I tried a few approaches -
1. Using the Impersonator Class -
http://www.codeproject.com/useritems...personator.asp

2. Using WebRequest object to write the file to the destination domain -
http://www.dotnet247.com/247referenc...42/211482.aspx

3.
http://www.codebetter.com/blogs/bren.../24/26730.aspx
Mapping to a network drive will not work in this scenario because of
design
requirements.

The 1st 2 approaches gave me the same error - Access denied to MyFile.txt.
This is a console application and the 2 domains I am referring to are on
the
same internal network and not across the internet.

Could someone please give me a pointer to solve this problem? Any help
with
this will be appreciated!

Thanks,
-Divya


You have to use authentication type 9 (LOGON32_LOGON_NEW_CREDENTIALS) in
your call to LogonUser.
Something like this will do.

IntPtr admin_token;
// use LOGON32_LOGON_NEW_CREDENTIALS as LogonType
if (LogonUser("remDomainAccount", "domain", "pwd", 9, 0, out
admin_token) != 0)
{
WindowsIdentity wid_admin = new WindowsIdentity(admin_token);
WindowsImpersonationContext wic = null;
try
{
wic = wid_admin.Impersonate();
System.IO.File.Copy("source", \\\\server\\share\\dest, true);
}
finally
{
if (wic != null) wic.Undo();
}
}
else
{
int ret =
Console.WriteLine(Marshal.GetLastWin32Error().ToSt ring());
}
Willy.
Nov 17 '05 #3

P: n/a
Thanks, Willy. I did what you have specified in the above reply. Now, my
program runs fine when it reads the parameters (user, domain, password etc)
from a XML file to move files across the internal network to a different
domain. This is a console application that should have the option of
specifying the parameters at the commandline prompt. When I specify the
parameters at commandline, it gives me a "Access denied" (access to the file
at the destination) error message.

Do you know how I can fix this? Any help in this regard will be appreciated.

Thanks,
-Divya

"Willy Denoyette [MVP]" wrote:

"Divya" <Di***@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
Hello,

I am trying to copy a file from one domain to another. I have the username
and password of the destination domain. I tried a few approaches -
1. Using the Impersonator Class -
http://www.codeproject.com/useritems...personator.asp

2. Using WebRequest object to write the file to the destination domain -
http://www.dotnet247.com/247referenc...42/211482.aspx

3.
http://www.codebetter.com/blogs/bren.../24/26730.aspx
Mapping to a network drive will not work in this scenario because of
design
requirements.

The 1st 2 approaches gave me the same error - Access denied to MyFile.txt.
This is a console application and the 2 domains I am referring to are on
the
same internal network and not across the internet.

Could someone please give me a pointer to solve this problem? Any help
with
this will be appreciated!

Thanks,
-Divya


You have to use authentication type 9 (LOGON32_LOGON_NEW_CREDENTIALS) in
your call to LogonUser.
Something like this will do.

IntPtr admin_token;
// use LOGON32_LOGON_NEW_CREDENTIALS as LogonType
if (LogonUser("remDomainAccount", "domain", "pwd", 9, 0, out
admin_token) != 0)
{
WindowsIdentity wid_admin = new WindowsIdentity(admin_token);
WindowsImpersonationContext wic = null;
try
{
wic = wid_admin.Impersonate();
System.IO.File.Copy("source", \\\\server\\share\\dest, true);
}
finally
{
if (wic != null) wic.Undo();
}
}
else
{
int ret =
Console.WriteLine(Marshal.GetLastWin32Error().ToSt ring());
}
Willy.

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.