Search code examples
vb.netpictureboxwinscpwinscp-net

Load picture from FTP to PictureBox with WinSCP .NET assembly


I am using WinSCP .NET assembly to transfer files by FTP. Couple days ago I developed new module to show pictures in PictureBox control. What I would like to achieve is to list picture's paths inside listbox or whatever else and then when click on this path to be able to open the picture in PictureBox. The point is pictures are on remote location on my FTP and I have no idea is it possible using WinSCP (FTP) to use get their path and then using the paths to show up given picture inside PictureBox. Anyone has idea is it possible or not?


Solution

  • You have to download the file to a local temporary file and load the file to the picture box. You cannot load the remote file directly.

    ' Unique temporary path 
    Dim tempPath As String = Path.GetTempFileName()
    ' Download the image
    session.GetFiles(RemotePath.EscapeFileMask(remoteImagePath), tempPath).Check()
    ' Load tempPath to picture box
    <your code here>
    ' Delete the temporary file
    File.Delete(tempPath)
    

    (I do not do VB.NET, so the syntax may not be 100% correct)