Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Pro Visual Basic 2005 For advanced Visual Basic coders working in version 2005. Beginning-level questions will be redirected to other forums, including Beginning VB 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Visual Basic 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 21st, 2006, 12:46 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems with FTP

Hello Everyone and thanks for your help in advance. I am working on an FTP client program to download some fairly large images files from an FTP site. The download begins correctly but nearly always, I receive the following exception:

System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

On a few rare occasions, the download will complete successfully. The code I am using is the following:

        Dim objFTPRequest As FtpWebRequest = CType(WebRequest.Create(URL), FtpWebRequest)
        objFTPRequest.Credentials = New NetworkCredential(UserName, Password)

        objFTPRequest.Method = WebRequestMethods.Ftp.DownloadFile

        Dim objFTPResponse As FtpWebResponse = CType(objFTPRequest.GetResponse, FtpWebResponse)

        Dim objStream As Stream = objFTPResponse.GetResponseStream

        'loop to read & write to file
        Dim fs As New IO.FileStream(LocalFile, IO.FileMode.Create)

        Dim buffer(2047) As Byte
        Dim read As Integer = 0
        Do
            read = objStream.Read(buffer, 0, buffer.Length)
            fs.Write(buffer, 0, read)
        Loop Until read = 0 'see Note(1)

        objStream.Close()
        fs.Flush()
        fs.Close()

        objStream.Close()
        objFTPResponse.Close()

I am not sure what I need to do to get this working. Any help on this topic would be greatly appreciated. Thanks.






Similar Threads
Thread Thread Starter Forum Replies Last Post
FTP problems rrlevron .NET Framework 2.0 1 December 20th, 2007 02:55 PM
ftp zaghmout C# 2005 2 November 6th, 2007 09:55 AM
FTP pakman Excel VBA 2 June 30th, 2005 05:58 AM
FTP pakman BOOK: Excel 2003 VBA Programmer's Reference 0 June 27th, 2005 04:24 AM
FTP? Nasimov Visual C++ 1 December 24th, 2003 09:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.