[net2.0] FTP - GetFileSize
- 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
)
回答
- response.ContentLength should give you the size
- 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
すべての返信
- response.ContentLength should give you the size
- Yes I read this in a thread, before.
U can write the Whole syntax?
- 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 - Oh!
Nearly the same, I did :D
Workz!
Than you very much!
greets reg3x
Thanks!!
it works
but the correct sintax is
MsgBox(
"Size : " & size)

