Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does File.Copy() from a network share to another share on the same machine copy the file over the network?

If my .NET client uses System.IO.File.Copy to copy a file from \server1\share1\file1.txt to \sever1\share2\file2.txt, does the file's data get read down to the client and then written back up to the server? If yes, is there any way a .NET client can copy a file on a server to another location on the same server without round-tripping the file? Does it make a difference if the destination share is the same as the source share?

like image 852
flipdoubt Avatar asked Feb 17 '09 02:02

flipdoubt


People also ask

How do I transfer files between computers on the same network?

To share a file or folder over a network in File Explorer, do the following: Right-click (or long-press) a file, and then select Show more options > Give access to > Specific people. Select a user on the network to share the file with, or select Everyone to give all network users access to the file.

How do you copy a file while it is being used by another process?

I tried copying it, and then accessing, but with File. Copy it threw an exception "File is being used by another process" again. But by simply copying this file in windows (ctrl+c) and pasting (ctrl+v) it worked.

Which of the following method do you use when you want to copy a file?

Method 1: Right-clickClick the name of the file or folder you wish to copy. Right-click the highlighted file or folder and click Copy. Go to the destination folder, right-click the destination folder and click Paste.


2 Answers

Yes it does. I can say this from personal experience with copying 10 GB Zip files between machines. The "client" machine was on a different coast of America than the two other machines. Between the two machines directly from one of them took a reasonable amount of time. Trying to initiate the copy from the machine on the other coast took ~10 hours :(

like image 82
JaredPar Avatar answered Nov 16 '22 00:11

JaredPar


This is an old question, but I don't think there is a correct answer here.

There are in fact 2 questions (3 questions, but the 3rd is redundant).

The first question is if a .Net process running on a (3rd) client machine copies a file from one network share to another network share, does it makes a difference if the source and target shares are on the same computer (different from the client) vs 2 different computers? The answer is clearly not. There is no mechanism, no secret tunnel between network shares. Data has to travel to the client and then to the other share. It does not make a difference if the operation is a copy or a move, and it actually does not make a difference if the shares are on the same computer as the client (and you really access folders as network shares with a UNC path and not as local folders).

The 2nd question is, how can this round-trip be avoided? Here are some suggestions:

  1. If the source and target are on the same share, moving a file does not require a round-trip, because the OS only updates the references in the file system.
  2. A process running on the machine with either the source or the target share can perform the copy without a roundtrip to the client. This process can be a remote copy etc if either of the hosts runs Linux. On a Windows host, you could install a WCF service that copies files when a request arrives from a client.
like image 33
cdonner Avatar answered Nov 15 '22 23:11

cdonner