Copy file to remote PC

  • Thread starter Thread starter alexia.bee
  • Start date Start date
A

alexia.bee

Hi all,

I need to copy a file from my PC to a remote PC.
The remote PC has different password and user name.
both PCs are on same domain not WORKGROUP.
Is there a .NET class or windows API which I can use to copy file?
does File.Copy supports that? I so, how should be the destination file
string format be?

Thanks.
 
It the computers are on a domain, then use a single domain account,
and grant the necessary read/write access (for the network share)
to account; i.e. the account will need to be able to read from the
source, and write (and create etc) to the destination. Then just
File.Copy it, or robocopy it if it is big.

Marc
 
does File.Copy supports that? I so, how should be the destination file
string format be?

something like \\computername\sharename\filename.extention might work,
never didf File.Copy but its a start...

//CY
 
I am afraid that file.copy or permission access is good for copying
file manually. it is not the same
if copying file prorammatically.

I saw there is a function called UserLogOm() but it is not good for
RPC in the domain.
 
Hi all,

I need to copy a file from my PC to a remote PC.
The remote PC has different password and user name.
both PCs are on same domain not WORKGROUP.
Is there a .NET class or windows API which I can use to copy file?
does File.Copy supports that? I so, how should be the destination file
string format be?

Thanks.

You might be able to do this using impersonation, see documentation
for WindowsIdentity.Impersonate...
 
I am afraid that file.copy or permission access is good for copying
file manually. it is not the same
if copying file prorammatically.

Um, sorry, but yes it is. Exactly the same. You just need to make sure
your code runs in the right account.

Marc
 
I am afraid that file.copy or permission access is good for copying
file manually. it is not the same
if copying file prorammatically.

I saw there is a function called UserLogOm() but it is not good for
RPC in the domain.


Don't know what RPC has to do with this.
You need to run your program in a domain account with appropriate privileges
to access the remote share.
In your program all you need to do is specify the UNC path of the remote
file, something like this:
File.Copy("localfile", @"\\servername\sharename\dir\dir\file");

If you don't run in a domain account, you will have to create a logon
session (LogonUser() ) and impersonate a domain account.
Another viable option is to create a session with the remote server/share
using the "net use ..." command line utility.

For instance when you issue following command (from the command line or by
code):

net use \\remServer\someShare myDomainPwd /user:myDomain\myDomainAccount

you will be able to copy a local file to the remote share like this:

...
File.Copy("somefile.txt", @"\\remServer\someShare\someremotefile.txt");
....


Willy.
 
Don't know what RPC has to do with this.
You need to run your program in a domain account with appropriate privileges
to access the remote share.
In your program all you need to do is specify the UNC path of the remote
file, something like this:
File.Copy("localfile", @"\\servername\sharename\dir\dir\file");

If you don't run in a domain account, you will have to create a logon
session (LogonUser() ) and impersonate a domain account.
Another viable option is to create a session with the remote server/share
using the "net use ..." command line utility.

For instance when you issue following command (from the command line or by
code):

net use \\remServer\someShare myDomainPwd /user:myDomain\myDomainAccount

you will be able to copy a local file to the remote share like this:

..
File.Copy("somefile.txt", @"\\remServer\someShare\someremotefile.txt");
...

Willy.

Hi all and thanks for the reply.

What is exactly the "sharenane"? is it the user name?
if I don't use "net use", where do i put username and password (and
domain if any) in the string when I copy the file?

thanks.
 
Don't know what RPC has to do with this.
You need to run your program in a domain account with appropriate
privileges
to access the remote share.
In your program all you need to do is specify the UNC path of the remote
file, something like this:
File.Copy("localfile", @"\\servername\sharename\dir\dir\file");

If you don't run in a domain account, you will have to create a logon
session (LogonUser() ) and impersonate a domain account.
Another viable option is to create a session with the remote server/share
using the "net use ..." command line utility.

For instance when you issue following command (from the command line or by
code):

net use \\remServer\someShare myDomainPwd /user:myDomain\myDomainAccount

you will be able to copy a local file to the remote share like this:

..
File.Copy("somefile.txt", @"\\remServer\someShare\someremotefile.txt");
...

Willy.

Hi all and thanks for the reply.

What is exactly the "sharenane"? is it the user name?
if I don't use "net use", where do i put username and password (and
domain if any) in the string when I copy the file?

thanks.



You don't seem to know what a domain login means I guess. You don't specify
the credentials when copying, you only need to make sure the current user is
logged on to the domain.
A "sharename" is the name of the File Share resource as it was *shared* by
the remote machine administrator.

Willy.
 
Back
Top