Click here to Skip to main content
15,921,169 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a code for downloading a file from a FTP Server:
VB
Dim outputStream As New FileStream(filePath + fileName, FileMode.Create)
Dim reqFTP As FtpWebRequest = DirectCast(FtpWebRequest.Create(New Uri(FTP + fileName)), FtpWebRequest)
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile
reqFTP.UseBinary = True
reqFTP.Credentials = New NetworkCredential(UserID, Password)
response = DirectCast(reqFTP.GetResponse(), FtpWebResponse)
ftpStream = response.GetResponseStream()
Dim cl As Long = response.ContentLength


Before start t download, I want to get the file size of the file selected by the user.
But when I'm using Dim cl As Long = response.ContentLength and displaying its value to MsgBox the value is -1, but the size of a file when download is finish the size is the same as in FTP Server.
Posted
Updated 3-Jun-11 2:34am
v3

1 solution

hansoctantan wrote:
But when I'm using Dim cl As Long = response.ContentLength and displaying its value to MsgBox the value is -1, but the size of a file when download is finish the size is the same as in FTP Server.A
That's correct, since you haven't downloaded any data yet.

You should use the GetFileSize[^] field to know in advance the selected file size.
 
Share this answer
 
Comments
hansoctantan 3-Jun-11 9:55am    
When I'm using
Const GetFileSize As String = WebRequestMethods.Ftp.GetFileSize
MsgBox(GetFileSize)
The result is "SIZE".
hansoctantan 3-Jun-11 10:11am    
I get it now, before downloading I must use
reqFTP.Method = WebRequestMethods.Ftp.GetFileSize
then the "response.ContentLength" will show its file size

Am I Right???
CPallini 3-Jun-11 12:01pm    
Much better, I guess.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900