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 = ""
        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

            stream = ftpResponse.GetResponseStream
            reader = New StreamReader(stream, Encoding.UTF8)
            writer = New StreamWriter(localFile, False)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

localFile should be a filename, not a folder.

Be a part of the DaniWeb community

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