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

前端 未结 5 1030
时光取名叫无心
时光取名叫无心 2021-01-11 13:12

If my .NET client uses System.IO.File.Copy to copy a file from \\server1\\share1\\file1.txt to \\sever1\\share2\\file2.txt

5条回答
  •  广开言路
    2021-01-11 13:55

    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.

提交回复
热议问题