如何检查C#是否可用文件服务器?

编程入门 行业动态 更新时间:2024-10-08 23:02:28
本文介绍了如何检查C#是否可用文件服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想从C#服务应用程序检查远程Windows 2003文件服务器的可用性. 仅文件共享测试是相关的(ping和其他测试在这里无济于事-即使禁用了文件共享或防火墙可以允许文件传输但拒绝ping,服务器也可以响应ping).我尝试了几种方法,但都不适合我的需求. 我想在没有管理员权限的情况下检查服务器的可用性,并且当服务器实际上不可用时,当共享脱机可用时,我不希望得到积极的回应. 如果共享文件夹脱机可用,即使服务器不可用,System.IO.DirectoryInfo.Exists(\\servername\sharedfolder)也会返回true . P/调用NetShareEnum()具有相同的缺陷". System.Management 命名空间中的WMI函数需要远程服务器上的管理员权限. 任何人都有一个想法如何进行正确的可用性检查?

I want to check availability of a remote Windows 2003 file server from a C# service application. Only file sharing test is relevant (ping and other tests do not help here - a server can respond to ping even when file sharing is disabled or firewall can allow file transfer but deny ping). I have tried several approaches but none suits my needs. I want to check server availability without admin rights and don''t want positive response when share is available offline while server is actualy unavailable. System.IO.DirectoryInfo.Exists(\\servername\sharedfolder) returns true if sharedfolder is available offline, even when server is not available. P/Invoke to NetShareEnum() has the same ''flaw''. WMI functions in System.Management namespace need admin rights on remote server. Anyone has an idea how to do proper availability check?

推荐答案

您好, 另一个解决方案是对服务器执行ping操作,如果收到响应,则表明服务器处于联机状态. :) Hello, Another solution is to ping the server, if you get a response the server is online. :) using System.Net.NetworkInformation;

PingReply pingReply; using (var ping = new Ping()) { pingReply = ping.Send("fileservername"); } if (pingReply.Status == IPStatus.Success) { Console.Write("Server is available"); } }

瓦莱里.

Valery.

一些想法: 1.将一个0字节的文件写入共享,然后将其删除. (需要写/删除访问权限) 2. 断开连接,然后重新连接到共享 [ ^ ]. (这将中断所有文件传输). 3.使用方法+检查远程服务器是否在tcp/445上监听 Some ideas: 1. Write a 0 byte file to the share, then delete it. (requires write/delete access) 2. Disconnect then reconnect to the share[^]. (this will break any file transfers). 3. Use your method + check if the remote server is listening on tcp/445

更多推荐

如何检查C#是否可用文件服务器?

本文发布于:2023-11-28 11:45:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642269.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件服务器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!