WinSCP, SFTP, ASP.NET, downloading file to memorystream? RRS feed

  • Question

  • User524410086 posted

    Dear all,

    I have a script in my ASP.NET page that gets a PDF file through FTP channel and puts it in a memorystream and then output it for the user.
    this script looks like this:

    Const username As String = "user"
    Const password As String = "password"
    Dim URI As String = "" & filename

    Dim request2 As FtpWebRequest = DirectCast(FtpWebRequest.Create(URI), FtpWebRequest)
    request2.Credentials = New System.Net.NetworkCredential(username, password)
    request2.Method = WebRequestMethods.Ftp.DownloadFile
    Dim response2 As FtpWebResponse = DirectCast(request2.GetResponse(), FtpWebResponse)
    Dim responseStream As IO.Stream = response2.GetResponseStream()

    Dim reader As New IO.StreamReader(responseStream)

    Dim buffer As [Byte]() = New [Byte](2046) {}

    Dim memstream As New IO.MemoryStream

    Dim read As Integer = 0
    read = responseStream.Read(buffer, 0, buffer.Length)
    'responseStream.Write(buffer, 0, read)
    memstream.Write(buffer, 0, read)
    Loop While read <> 0

    Response.AddHeader("Content-Disposition", "inline; filename=" + filename)
    Response.ContentType = "Application/pdf"


    Now, i want to switch to SFTP and I am using WinSCP. I managed to get the link ready, however, i am still struggling with the way to download the PDF file to a memorystream and then output it for the user.
    Can you please help me to apply SFTP using WinSCP on the above script?
    Thanks in advance.

    Monday, August 31, 2009 7:04 AM

All replies

  • User524410086 posted

    guys! i came to know that i can't do this with WinSCP, the file has to be downloaded temporarily.

    So, if you have any other suggestion other than WinSCP for SFTP to download a file to a memorystream, please help?

    Wednesday, September 2, 2009 2:57 AM