I want to test a given IP and login detail to see whether the FTP server is active/details are correct. Nothing more.
I have looked on the web for a solution but none seem simple/eloquent as, for example, using the Ping class to ping and check for a server. I have the following, which doesn't work:
static private void testConntecion()
{
FtpWebRequest requestDir = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://172.29.200.158/"));
requestDir.Credentials = new NetworkCredential("dvm_user", "dvm");
try
{
FtpWebResponse response = (FtpWebResponse)requestDir.GetResponse();
Console.WriteLine("Cool Beans");
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
}
I have also tried:
FtpWebRequest requestDir = (FtpWebRequest)FtpWebRequest.Create("ftp://172.29.200.158/");
Error message: System.Net.WebException: The requested URI is invalid for this FTP command. at System.Net.FtpWebRequest.GetResponse()
Thanks in advance.
You need to set the Method on the ftp request:
requestDir.Method = WebRequestMethods.Ftp.ListDirectory;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With