Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use File.Copy C# method to copy files over LAN?

Tags:

c#

winforms

lan

I want to make a WinForms Application that can copy files over a LAN. Using File.Copy seems a straightforward way to do this. The example given here shows how to copy a file to a different directory on the same computer. How can I use File.Copy to copy files from one computer to another which belongs to the same LAN?

like image 600
Xel Avatar asked Feb 13 '12 05:02

Xel


2 Answers

you can try

   File.Copy(@"\\server\sourceFileFolder\file1", @"\\server2\destinationFileFolder\file1");

also make sure to use UNC path.. here are some references. - Link - Link - Link

like image 147
Anantha Sharma Avatar answered Sep 23 '22 15:09

Anantha Sharma


Something like this

File.Copy(
    "C:\path\yourfile.txt", 
    "\\remote_hostname\path\destinationfile.txt");
like image 35
Dmitry Savy Avatar answered Sep 23 '22 15:09

Dmitry Savy