Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB VB.NET FTP
Hi everyone,
I have a program that downloads file from FTP Server.
This is my code for downloading files
	Dim request As FtpWebRequest = Nothing
        Dim response As FtpWebResponse = Nothing
        request = DirectCast(FtpWebRequest.Create(New Uri(clsDownload(index).FTPURL)), FtpWebRequest)
        request.ServicePoint.ConnectionLimit = maxDownload
        request.Method = WebRequestMethods.Ftp.DownloadFile
        request.UseBinary = True
        request.UsePassive = True
        request.KeepAlive = False
        request.Credentials = New NetworkCredential(username, password)
        response = DirectCast(request.GetResponse(), FtpWebResponse)
        Dim ftpStream As Stream = response.GetResponseStream()
 
        Dim bufferSize As Integer = 2048
        Dim readCount As Integer
        Dim buffer As Byte() = New Byte(bufferSize - 1) {}
        readCount = ftpStream.Read(buffer, 0, bufferSize)
        While readCount > 0
            outputStream.Write(buffer, 0, readCount)
            readCount = ftpStream.Read(buffer, 0, bufferSize)
        End While
        outputStream.Close()
The above code runs fine when the filesize is less than 10MB.
When file is greater than 10MB the program can't download the file.
Well at first the file is downloaded, let say the file is 11000KB the program will download the file to 10999 the last 1KB causes error... don't know whats wrong with my code.
 
This is the error
The underlying connection was closed: An unexpected error occurred on a receive.
 
I just try using different bufferSize(1000, 32 * 1024) but same error occured...
Posted 26-Jun-12 23:33pm
Edited 27-Jun-12 3:07am
v3
Comments
Bernhard Hiller at 27-Jun-12 6:40am
   
Did you check that the file on the server is OK (e.g. by downloading with Internet Explorer)?
How do you know that the downloaded file is not OK? Do you get any error messages?
Does that behavior also happen with a larger bufferSize (e.g. 1048576)?
hansoctantan at 27-Jun-12 8:05am
   
I will try it...
hansoctantan at 27-Jun-12 8:09am
   
and yes I get a runtime error
hansoctantan at 27-Jun-12 8:14am
   
Yes it successfully downloaded the file in mozilla browser manually...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Check this question might help you-
Download large file from FTP C#[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

string[] files ={ "UserList.csv", "Catalog.csv", "DeleteUser.csv" };
 
                Sftp sftp = new Sftp(ftpServerIPAndPort, ftpUserName, decryptor(ftpPassword));
 
                sftp.Connect(22);
                foreach (string filename in files)
                {
                   sftp.Get(ftpRootFolder + filename, Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + @"\Ayush\CSVFilesBackup/" + filename);
                  
                }
 
                       
This Example Fetch these three files from SFTP of any size........... Try This
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 580
1 ashok rathod 159
2 CPallini 140
3 CHill60 130
4 BillWoodruff 125
0 Sergey Alexandrovich Kryukov 9,543
1 OriginalGriff 6,984
2 CPallini 5,820
3 George Jonsson 4,017
4 Gihan Liyanage 3,266


Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 27 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100