2

Does File.Move / File.Copy uses NIC to move files from one computer to another? If not, how could I program in C# to use NIC to transfer files from one computer to another?

Gopi
  • 5,656
  • 22
  • 80
  • 146

3 Answers3

1

Yes, File.Move and File.Copy will work on network shares, for example:

File.Copy(@"C:\Filename.txt", @"\\hostname\c$\Filename.txt");
File.Copy(@"C:\Filename.txt", @"X:\Filename.txt"); // If the network share was mapped to X:\

This will work if your user has access to the share, or if you have previously accessed the share using different credentials in Windows Explorer. If not, you will get a System.UnauthorizedAccessException and you will have to supply credentials.

Community
  • 1
  • 1
Anlo
  • 3,228
  • 4
  • 26
  • 33
0

If by NIC you mean Network Interface Card then yes it will use it to move files from one computer to the other, but only indirectly through the operating system.

The file procedures will talk to the OS, which in turn will take care of using the NIC if and when it's needed.

You have to setup Windows to be in a network.

What you do would look something like:

File.Copy(@"C:\foo.bar", @"\\nas\data\foo.bar");

But if you map a network drive it could also look like:

File.Copy(@"C:\foo.bar", @"n:\data\foo.bar");

It all depends on your situation.

Meine
  • 53
  • 8
0

File.Move / File.Copy work on a much higher abstraction level than the actual hardware (your NIC).

It is possible that (depending on the path of the file you copy) the operating system decides to use the NIC, just local disks, an USB connection or whatever else.

You dont have to care about that, you just have to assure that the path of the target is correct (local file path, or UNC path or else)

fixagon
  • 5,506
  • 22
  • 26