Getting the file size from a FTP Server

Hi,

I want to get a file size from an FTP server.

I can use this method because the ftp server doesn't support this command:

WebRequestMethods.Ftp.GetFileSize

So i decided to get the file size in this way:

FtpWebRequest myReq = (FtpWebRequest)WebRequest.Create(ftp://ftp.ftp.ftp/);

myReq.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

Stream s = myReq.GetResponse().GetResponseStream();

StreamReader reader = new StreamReader(s);

MessageBox.Show(reader.ReadToEnd());

My question is how can i get, just the file size, and not all the string...

I don't want to split my string to an array and getting from the array the file size because i don't want to lose performance...

 

Help me...



Answer this question

Getting the file size from a FTP Server

  • Hawkmoth

    I dont think there is a way out except for parsing the response from the server
  • jiggs

    This isn't my problem...

    My problem is how can i get from this repsonse only the file size


  • Krixna

    I tried the following sample and I could get  just the file
    that I am interested in. Thatway you don't need to parse through
    n number of entries and get the size of the file

    May be this would help

     

    using System;
    using System.Net;
    using System.Net.Sockets;
    using System.Text;
    using System.IO;

    public class Test
    {
     public static void Main()
     {
      FtpWebRequest myReq = (FtpWebRequest)WebRequest.Create("ftp://192.168.0.2/adsutil.vbs");
      myReq.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
      myReq.UsePassive = false;
      Stream s = myReq.GetResponse().GetResponseStream();
      StreamReader reader = new StreamReader(s);
      Console.WriteLine(reader.ReadToEnd());
      s.Close();
      reader.Close();
     }
    }



  • Getting the file size from a FTP Server