Network file copy in .NET

被刻印的时光 ゝ 提交于 2019-12-01 09:36:10

问题


I have an Ubuntu box running a Samba share open to everyone. I can access it via \ip address so I know I have full access to it.

From within my application I am trying the following but it will not work via the ip address only the DNS name.

// val = ip address
File.Copy("\\\\" + val + "\\share\\vSphere\\vSphere.exe", Temp + "vSphere.exe", true);

I need to use the IP Address as people who are VPN'ing in won't be able to have the program access the dns name only the ip address.


回答1:


First, try by giving IP address as below

File.Copy(@"\\192.100.1.23\share\vSphere\vSphere.exe", Path.combine(Temp ,"vSphere.exe"), true);

if error exist try using impersonate, give user name and password

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

WindowsIdentity idnt = new WindowsIdentity(username, password);

WindowsImpersonationContext context = idnt.Impersonate();

File.Copy(@"\\192.100.1.23\share\vSphere\vSphere.exe", Path.combine(Temp ,"vSphere.exe"), true);

context.Undo();


来源:https://stackoverflow.com/questions/7811017/network-file-copy-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!