简体   繁体   中英

How to copy files from remote windows machines to another windows machine using C#?

I have a folder in which log files are created continuously through a file simulator. On completion of creation of each file, a background windows service which is a FolderWatcher , should copy each file to a central windows server.

I have used File.Copy() to transfer the files from one machine to another. The issue is my background windows service is not able to know whether the file to be copied is still in use.

Is there any way to know that the file is still in use? I know if we try to open the file which is in use, it will throw exception.

捕获异常并将文件放在文件列表中,以便以后再次尝试。

I would check if the file is in use first, then if it is, add it to a queue that is periodically checked and move the file when its free.

See this stackoverflow question to determine how to see if a file is already open.

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