Topic "WinSCP, SFTP, ASP.NET, downloading file to memorystream?"

Author Message
alasaadi
[View user's profile]

Joined: 2009-08-31
Posts: 2
Location: Bahrain
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 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
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.
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24993
Location: Prague, Czechia
I'm sorry, but you cannot do this with WinSCP. You have to download it to temporary file.
_________________
Martin Prikryl
alasaadi
[View user's profile]

Joined: 2009-08-31
Posts: 2
Location: Bahrain
Sad that's sad.. but thanks for the response.
ephraimdov
[View user's profile]

Joined: 2015-06-26
Posts: 1
Location: UAE
string memString = "Memory test string !!";
// convert string to stream
byte[] buffer = Encoding.ASCII.GetBytes(memString);
MemoryStream ms = new MemoryStream(buffer);
//write to file
FileStream file = new FileStream("d:\\file.txt", FileMode.Create, FileAccess.Write);
ms.WriteTo(file);

Source : MemoryStream to File

Dov
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License