Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

m_mittal

DOwnload to memory stream

Is this functionality added ? Can we download a file to memorystream insead of a local folder
alasaadi

:( that's sad.. but thanks for the response.
alasaadi

WinSCP, SFTP, ASP.NET, downloading file to MemoryStream?

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 = "ftp://192.168.10.10/" & filename
 
Dim request2 As FtpWebRequest = DirectCast(FtpWebRequest.Create(URI), FtpWebRequest)
request2.Credentials = New NetworkCredential(username, password)
request2.Method = WebRequestMethods.Ftp.DownloadFile
Dim response2 As FtpWebResponse = DirectCast(request2.GetResponse(), FtpWebResponse)
Dim responseStream As Stream = response2.GetResponseStream()
 
Dim reader As New StreamReader(responseStream)
 
Dim buffer As [Byte]() = New [Byte](2046) {}
 
Dim memstream As New MemoryStream
 
Dim read As Integer = 0
Do
    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"
Response.BinaryWrite(memstream.ToArray)
Response.Flush()
Response.End()
 
responseStream.Close()
memstream.Flush()
memstream.Close()
responseStream.Close()

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.