473,441 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

Copy a file from 1 domain to another

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
3 15958
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Paul | last post by:
Dear All, I want to use web form to upload my file and copy the file to another machine. I can upload the file, but when I copy the file(file.CopyTo(".....", true)) to another machine(map...
5
by: Patrice Dargenton | last post by:
Hello, I have to convert an xml file to another xml file that is very similar, but some content are different, and the names of some nodes are different. In fact it's a response to a message :...
0
by: Grey | last post by:
I have a ASP.NET web application which is required to copy file from windows server to Novell Netware server. I have used impersonation to connect to Netware server. The application works fine when...
9
by: MAF | last post by:
Does anyone know why in 2005 I might be getting this error everytime I try and recompile? Error 226 Unable to copy file "obj\Debug\myfile.dll" to "bin\Debug\myfile.dll". The process cannot...
3
by: Christopher Lusardi | last post by:
If I want to copy one file to another how do I do that? I want to do this even if the second file already exists. Thanks, Christopher Lusardi
2
by: LiveCycle | last post by:
Hi, I'm writing a web service, and, as part of its function, I want it to copy a file from a remote server and place that file on the local web server under another name. However, I always get...
17
by: Eric_Dexter | last post by:
def simplecsdtoorc(filename): file = open(filename,"r") alllines = file.read_until("</CsInstruments>") pattern1 = re.compile("</") orcfilename = filename + "orc" for line in alllines: if not...
9
rizwan6feb
by: rizwan6feb | last post by:
Hello everybody. I need help on how to use copy function to copy file from one computer to another ( or any other way i can copy the file). The computers are on a local network.
2
by: foss | last post by:
hi all, I am not able to copy file from a directory in the server to another directory. Here, the source is outside the web root directory and the destination is inside the web root directory. ...
1
by: ram patidar | last post by:
how i can copy the contents of one file to another file? a block at a time usng win32 API? ram patidar
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.