System.Net.FtpWebRequest GetDateTimestamp is calling

Next test jobs ...

  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 next 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 the error message:

Test method test2 threw an exception: System.Net.WebException: The remote server returned an error: (550) File not available (for example, file not found, access denied).

UPDATE: I tried to use another ftp site (unix) that uses the default port # so the url " ftp://myserver.com/dev " - and GetDateTimestamp () still dies with the same error.

I've updated the subject line and body of the question to reflect my request correctly.

0


source to share


2 answers


Please add additional information.

Guess you are trying

  • a) Do ls on FTP server (works)
  • b) Get timestamp from FTP server (not working)

Since everything else looks the same (address, etc.), I am assuming they both look at the same data. I would guess that ls

only works when you are connected. But what timestamp are you trying to get there? The documentation for WebRequestMethods.Ftp.GetDateTimestamp says



Represents the FTP MDTM method that is used to extract a date stamp from a file to an FTP server.

(Underlined by me)

Which file? As far as I can see, you only specified the folder (not sure if this works)? Have you tried this with ftp://myserver.com/dev/text.txt "

+2


source


It looks like the URI in the two examples is the same, your test cases don't match the problem description. Can you be more specific?



(In general, it's easiest to add one piece of sample code with one or two highlighted lines.)

0


source







All Articles