简体   繁体   English

c#File.Copy从\\\\ 127.0.0.1

[英]c# File.Copy from \\127.0.0.1

In C# (.NET 2.0), I have the following line of code: 在C#(.NET 2.0)中,我具有以下代码行:

File.Copy(fileName, @"C:\Temp\someDir\SomeFile.jpg"); 

where fileName is "\\\\127.0.0.1\\someDir\\someFile.jpg". 其中fileName为“ \\\\ 127.0.0.1 \\ someDir \\ someFile.jpg”。 I get an IOException that says "The system detected a possible attempt to compromise security. Please ensure that you can contact the server that authenticated you." 我收到一个IOException,上面写着:“系统检测到可能危害安全性的尝试。请确保您可以与通过身份验证的服务器联系。”

Any idea what is going on here? 知道这里发生了什么吗?

Thanks, Scott 谢谢,斯科特

The File class accepts path that can be UNC path for server or share. File类接受的路径可以是服务器或共享的UNC路径。 So in your case File.Copy is assuming that the fileName is a UNC path of a server or share hence the copy method throws exception 因此,在您的情况下,File.Copy假定fileName是服务器或共享的UNC路径,因此copy方法将引发异常

File.Copy("\\127.0.0.1\someDir\someFile.jpg", @"C:\Temp\someDir\SomeFile.jpg");

I would suggest you try to use WebClient.UploadFile 我建议您尝试使用WebClient.UploadFile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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