Click here to Skip to main content
15,902,860 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am trying to download a file from my server.
It resides in the root directory of my online site: (root)\ftp1\GraphPlanets.zip
The ftpuser and password on my server open to a folder and it is set to: \ftp1\

Here is my code to download:

VB
' Create the request.
        Dim request As FtpWebRequest = FtpWebRequest.Create("ftp://ftp.philosophaie.com/GraphingPlanets.zip")
        request.Credentials = New NetworkCredential("ftpuser", "pass")
        request.KeepAlive = False
        request.UseBinary = True
        request.UsePassive = True
        request.Method = WebRequestMethods.Ftp.DownloadFile

        ' Save the file to the file system.
        Using response As System.Net.FtpWebResponse = CType(request.GetResponse, System.Net.FtpWebResponse)
            Using responseStream As IO.Stream = response.GetResponseStream
                Using fs As New IO.FileStream(Server.MapPath("\ftp1\GraphingPlanets.zip"), IO.FileMode.Create)
                    Dim buffer(2047) As Byte
                    Dim read As Integer = 0
                    Do
                        read = responseStream.Read(buffer, 0, buffer.Length)
                        fs.Write(buffer, 0, read)
                    Loop Until read = 0
                    responseStream.Close()
                    fs.Flush()
                    fs.Close()
                End Using
                responseStream.Close()
            End Using
            response.Close()
        End Using
Posted
Comments
Thanks7872 23-May-13 3:36am    
Then what is the issue?
teledexterus 23-May-13 4:45am    
.net 4.0 and asp.net 4.0
Thanks7872 23-May-13 4:59am    
I asked you about the problem with the above code?
teledexterus 23-May-13 5:11am    
Changed from Member0_000_001 to arsTelepathiae.

The problem is that it does nothing when you click the button. Previous revision had errors due to the ftp account and the path to the server vs path of the ftp.

1 solution

Are you trying to make a client side app in VB that will download files from your FTP server?

If so, you might check out the following article:

An FTP client library for .NET 2.0[^]

Sure that is for .NET 2.0, but it shouldn't be to hard to convert using the Visual Studio Conversion Wizard.

http://msdn.microsoft.com/en-us/library/dd483478(v=vs.100).aspx[^]


Hope this helps.
 
Share this answer
 
v2

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