Retrieve and display Image from FTP folder using C# and VB.Net in ASP.Net

Last Reply 11 months ago By dharmendr

Posted 11 months ago

I have store the image in FTP folder but dont know how to retrieve the image from the folder and display in my webpage..

Please give me some ideas and lead me to finish this task

Posted 11 months ago

Refer below article.

Display List of files from FTP folder with Download option in ASP.Net using C# and VB.Net

Once you get the list use below article to display the binary image in image control.

Display image in Image control based on DropDownList selection in ASP.Net

Posted 11 months ago

Hi Sir,

i want to get image from my FTP folder and want to display in my browser page

Posted 11 months ago

Hi Dev@KKM,

Check with the below code.


protected void Page_Load(object sender, EventArgs e)
    //FTP Server URL.
    string ftp = "";

    //FTP Folder name. Leave blank if you want to list files from root folder.
    string ftpFolder = "Uploads/";
        string fileName = "Desert.jpg";
        //Create FTP Request.
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftp + ftpFolder + fileName);
        request.Method = WebRequestMethods.Ftp.DownloadFile;

        //Enter FTP Server credentials.
        request.Credentials = new NetworkCredential("Username", "Password");
        request.UsePassive = true;
        request.UseBinary = true;
        request.EnableSsl = false;

        //Fetch the Response and read it into a MemoryStream object.
        FtpWebResponse response = (FtpWebResponse)request.GetResponse();
        using (MemoryStream stream = new MemoryStream())
            string base64String = Convert.ToBase64String(stream.ToArray(), 0, stream.ToArray().Length);
            Image1.ImageUrl = "data:image/png;base64," + base64String;
    catch (WebException ex)
        throw new Exception((ex.Response as FtpWebResponse).StatusDescription);


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    'FTP Server URL.
    Dim ftp As String = ""
    'FTP Folder name. Leave blank if you want to list files from root folder.
    Dim ftpFolder As String = "Uploads/"
        Dim fileName As String = "Desert.jpg"
        'Create FTP Request.
        Dim request As FtpWebRequest = CType(WebRequest.Create(ftp & ftpFolder & fileName), FtpWebRequest)
        request.Method = WebRequestMethods.Ftp.DownloadFile
        'Enter FTP Server credentials.
        request.Credentials = New NetworkCredential("Username", "Password")
        request.UsePassive = True
        request.UseBinary = True
        request.EnableSsl = False
        'Fetch the Response and read it into a MemoryStream object.
        Dim response As FtpWebResponse = CType(request.GetResponse(), FtpWebResponse)
        Using stream As MemoryStream = New MemoryStream()
            Dim base64String As String = Convert.ToBase64String(stream.ToArray(), 0, stream.ToArray().Length)
            Image1.ImageUrl = "data:image/png;base64," & base64String
        End Using
    Catch ex As WebException
        Throw New Exception((TryCast(ex.Response, FtpWebResponse)).StatusDescription)
    End Try
End Sub