Click here to Skip to main content
14,549,638 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a code for downloading a file from a FTP Server:
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100