I am using third party FTP server to upload files there. But before uploading, I want to implement test connection functionality, so user can test that he has entered correct credentials or not.
The problem is that if user don't have access to list the directory. So my code will not work for testing connection even he has access for file upload, because right now I am using WebRequestMethods.Ftp.ListDirectory
method to test connection and its working as expected.
bool testResult = false;
try
{
FtpWebRequest request =
(FtpWebRequest)WebRequest.Create(objVMTestFTPConnectionRequest.FTPAddress);
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials =
new NetworkCredential(
objVMTestFTPConnectionRequest.UserName, objVMTestFTPConnectionRequest.Password);
WebResponse response = request.GetResponse();
testResult = true;
}
catch (Exception exception)
{
throw;
}
return testResult;
I am getting following error when I remove that ListDirectory
method
The requested URI is invalid for this FTP command.
Just help me if I can do this without using that method.