質問する質問する
 

回答済み[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)