Following test works...
public void test1()
{
string server="ftp://myserver.com/dev";
string userName="myusername";
string password="mypassword";
FtpWebRequest req = (FtpWebRequest)WebRequest.Create( server );
req.Credentials = new NetworkCredential( userName, password );
req.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
req.Timeout = 30000;
req.UseBinary = false;
req.EnableSsl = false;
req.UsePassive = false;
req.KeepAlive = true;
using( FtpWebResponse resp = (FtpWebResponse)req.GetResponse() )
{
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
{
string fileRecord = sr.ReadLine();
while (fileRecord != null)
{
Console.WriteLine( fileRecord );
fileRecord = sr.ReadLine();
}
}
}
}
While the following test fails...
public void test2()
{
string server="ftp://myserver.com/dev";
string userName="myusername";
string password="mypassword";
FtpWebRequest req = (FtpWebRequest)WebRequest.Create( server );
req.Credentials = new NetworkCredential( userName, password );
req.Method = WebRequestMethods.Ftp.GetDateTimestamp;
req.Timeout = 30000;
req.UseBinary = false;
req.EnableSsl = false;
req.UsePassive = false;
req.KeepAlive = true;
using( FtpWebResponse resp = (FtpWebResponse)req.GetResponse() )
{
using( StreamReader sr = new StreamReader( resp.GetResponseStream() ) )
{
Console.WriteLine( resp.LastModified );
}
}
}
with error message:
Test method test2 threw exception: System.Net.WebException: The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
UPDATE: I tried with another ftp site (unix) that uses the default port#, so the url is "ftp://myserver.com/dev" - and the GetDateTimestamp() still dies with the same error.
I have updated the subject line and the body of the question to reflect my query properly.