• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
.NET Framework Developer Center
 
 
Home
 
 
Library
 
 
Learn
 
 
Downloads
 
 
Support
 
 
Community
 
 
Forums
 
 
 
.NET Framework Developer Center > .NET Development Forums > .NET Framework Networking and Communication > [net2.0] FTP - GetFileSize
Ask a questionAsk a question
Search Forums:
  • Search .NET Framework Networking and Communication Forum Search .NET Framework Networking and Communication Forum
  • Search All .NET Development Forums Search All .NET Development Forums
  • Search All MSDN Forums Search All MSDN Forums
 

Answer[net2.0] FTP - GetFileSize

  • Saturday, September 24, 2005 10:26 PMreg3x Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    Hi!
    I want to retrieve the Filesize of a file
    on  a ftp-server.
    I tried this listing :

            Dim size As String
            Dim reader As StreamReader = Nothing

            Try
                Dim request As FtpWebRequest = WebRequest.Create("ftp://server.com")
                request.Credentials = New NetworkCredential("anonymous", "anonymous")
                request.Method = WebRequestMethods.Ftp.GetFileSize
                Dim response As FtpWebResponse = request.GetResponse
                reader = New StreamReader(response.GetResponseStream)
                size = reader.ReadLine()
                MsgBox("Size : " + size)
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally

                If reader IsNot Nothing Then
                    reader.Close()
                End If

            End Try

    ... You see. It connects to a ftp-server and (I think) retrieves the Filesize.
    But the read line, which is put into the Variable "size" is empty.
    (I tested the Code with real ftp-usernames and logons on my server.)

    You can help me, to retrieve the FileSize of an File on a ftp-Server?

    , reg3x
    (I'm German Big Smile)
    • ReplyReply
    • QuoteQuote
     

Answers

  • Sunday, September 25, 2005 3:00 AMDurgaprasad GortiModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0
    response.ContentLength should give you the size
    • ReplyReply
    • QuoteQuote
     
  • Sunday, September 25, 2005 3:39 PMDurgaprasad GortiModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0
          Dim size As Integer
            Dim reader As StreamReader = Nothing

            Try
                Dim request As FtpWebRequest = WebRequest.Create("ftp://server.com")
                request.Credentials = New NetworkCredential("anonymous", "anonymous")
                request.Method = WebRequestMethods.Ftp.GetFileSize
                Dim response As FtpWebResponse = request.GetResponse
                size = response.ContentLength
                MsgBox("Size : " + size)
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally

                If reader IsNot Nothing Then
                    reader.Close()
                End If

            End Try
    • ReplyReply
    • QuoteQuote
     

All Replies

  • Sunday, September 25, 2005 3:33 PMreg3x Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    Yes I read this in a thread, before.
    U can write the Whole syntax?
    • ReplyReply
    • QuoteQuote
     
  • Sunday, September 25, 2005 4:34 PMreg3x Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    Oh!
    Nearly the same, I did :D
    Workz!
    Than you very much!

    greets reg3x
    • ReplyReply
    • QuoteQuote
     
  • Friday, March 16, 2007 12:23 AMtuzojazz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Thanks!!

    it works

    but the correct sintax is

     

    MsgBox("Size : " & size)

    • ReplyReply
    • QuoteQuote
     
Need Help with Forums? (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
Terms of Use
|
Trademarks
|
Privacy Statement