提出问题提出问题
 

已答复[net2.0] FTP - GetFileSize

  • 2005年9月24日 22:26reg3x 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    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)

答案

  • 2005年9月25日 3:00Durgaprasad Gorti版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    response.ContentLength should give you the size
  • 2005年9月25日 15:39Durgaprasad Gorti版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
          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

全部回复

  • 2005年9月25日 3:00Durgaprasad Gorti版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    response.ContentLength should give you the size
  • 2005年9月25日 15:33reg3x 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Yes I read this in a thread, before.
    U can write the Whole syntax?
  • 2005年9月25日 15:39Durgaprasad Gorti版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
          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
  • 2005年9月25日 16:34reg3x 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Oh!
    Nearly the same, I did :D
    Workz!
    Than you very much!

    greets reg3x
  • 2007年3月16日 0:23tuzojazz 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    Thanks!!

    it works

    but the correct sintax is

     

    MsgBox("Size : " & size)