Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27421

VS 2008 FTP Help needed

$
0
0
Hi everyone,

I need to connect to a site, change directory and then download a file. I have been searching on using the FTPWebRequest and got the following code but it does not show how to change the directory first and then specify the file. Can someone show me how to do this with either the code below or a better way of doing it all?

Also, I have a username and password I need to login with for the ftp.

Thanks!!

Code:

    Public Shared Sub FTP1()
        ' Get the object used to communicate with the server.
        Dim request As FtpWebRequest = DirectCast(WebRequest.Create("ftp://www.contoso.com/test.htm"), FtpWebRequest)
        request.Method = WebRequestMethods.Ftp.DownloadFile

        ' This example assumes the FTP site uses anonymous logon.
        request.Credentials = New NetworkCredential("anonymous", "janeDoe@contoso.com")

        Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)

        Dim responseStream As Stream = response.GetResponseStream()
        Dim reader As New StreamReader(responseStream)
        Console.WriteLine(reader.ReadToEnd())

        Console.WriteLine("Download Complete, status {0}", response.StatusDescription)

        reader.Close()
        response.Close()
    End Sub


Viewing all articles
Browse latest Browse all 27421

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>