简体   繁体   中英

Machine to Machine File transfer

I need to transfer text files located at a location from one machine to another machine through .NET for every one second. Later again i require to transfer vice-versa. Please help me how to acheive through C#.NET

In case the machines are on the same network, you might also try and work with network shares. Then you could use \\\\machine\\folder as destination folder for your files using the normal File.Copy method.

To transfer a file from machine A to machine B you could use the Copy method. Assuming you have administrative privileges on machine B you could use the following code to copy a file every second from machine A to machine B:

ThreadPool.RegisterWaitForSingleObject(
    new ManualResetEvent(false), 
    (state, timedOut) => 
    {
        // TODO: error handling
        File.Copy("c:\someFile.txt", "\\machineB\c$\someFile.txt", true);
    }, 
    null, 
    TimeSpan.FromSeconds(1), 
    false);

If you don't have administrative privileges on machine B you could use shares:

File.Copy("c:\someFile.txt", "\\machineB\someShare\someFile.txt", true);

您还可以每1秒使用计算机类和计时器来移动文件

If you have an FTP server on each machine, you can use a C# FTP Client Library .

You may also want to consider one of the P2P libraries out there (no FTP server required).

Whether you can transfer the files in the time available depends on the file size and bandwidth more than the means you use to transfer the files, though some protocols have more overhead than others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM