Good Day!
I'm downloading files from ftp site using vb .net but unfortunately I encountered exception - "Access to the path 'C:\samplefolder' is denied."
Don't know what exactly is the problem and as I searched the codes are good and running.. Please do help, I'll really appreciate it... Thanks and Godbless everyone!

Private Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownload.Click
        Dim localFile As String = "C:\samplefolder"
        Dim remoteFile As String = "/sample.txt"
        Dim host As String = "ftp://10.0.201.77"
        Dim user_name = "username"
        Dim password = "password"
        Dim URI As String = host & remoteFile
        Dim ftpRequest As FtpWebRequest = CType(WebRequest.Create(URI), FtpWebRequest)
        ftpRequest.Credentials = New NetworkCredential(username, password)
        ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile

        Dim ftpResponse As FtpWebResponse = CType(ftpRequest.GetResponse, FtpWebResponse)
        Dim stream As Stream = Nothing
        Dim reader As StreamReader = Nothing
        Dim writer As StreamWriter = Nothing

        Try
            stream = ftpResponse.GetResponseStream
            reader = New StreamReader(stream, Encoding.UTF8)
            writer = New StreamWriter(localFile, False)
            writer.Write(reader.ReadToEnd)
            Return
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.