如何检查FTP连接?
问题描述:
有没有检查一个FTP连接(包括主机,端口,用户名和密码)的简单,快速的方法是有效的和工作?我使用C#。谢谢你。
Is there a simple, fast way to check that a FTP connection (includes host, port, username and password) is valid and working? I'm using C#. Thank you.
答
您可以尝试使用 System.Net.FtpWebRequest
,然后只检查 GetResponseStream
方法。
You could try using
System.Net.FtpWebRequest
and then just check the GetResponseStream
method.
因此,像
System.Net.FtpWebRequest myFTP = new System.Net.FtpWebRequest
//Add your credentials and ports
try
{
myFTP.GetResponseStream();
//set some flags
}
catch ex
{
//handle it when it is not working
}