EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Download file via sftp to string

Posted: 09/18/2015 17:50:17
by Philipp Bundschuh (Basic support level)
Joined: 09/18/2015
Posts: 5

I have modified the sample console application vb.net to my needs. Just connecting to an ssh, crawling an directory and listing the content. Works fine, but now I wanna read a remote file to an string, so that I can parse it for my further needs. How can I do that?

Posted: 09/18/2015 18:13:34
by Ken Ivanov (Team)

Hi Philipp,

As what files contain are essentially sequences of bytes rather than strings, you would need to convert those byte sequences to strings using some bytes-to-string conversion mechanism (often called 'encoding') to be able to parse them. One of the most commonly used encodings are UTF8 and UTF16, but there are others too. The encoding which you are going to use to convert file contents to a string should match the encoding applied by the writer on file creation stage.

So, what you need to do is:

1) Download the remote file with DownloadStream or DownloadFile method. You'll end up with a sequence of bytes.

2) Read the downloaded file contents to memory (if the files are supposed to be small).

3) Convert the byte sequence to string using an appropriate encoding. You can do that with native .NET Encoding class or with built-in SecureBlackbox functions (e.g. SBStrUtils.Unit.UTF8ToStr).

Posted: 09/18/2015 18:34:59
by Philipp Bundschuh (Basic support level)
Joined: 09/18/2015
Posts: 5

Hi Ken,

I didn't get the DownloadStream to work. :-(
Do you have an short example, how to implement the downloadstream-function?

Posted: 09/18/2015 18:57:55
by Ken Ivanov (Team)


It is fairly straightforward. Please use the code below as a guide:

Dim stream as new MemoryStream

SftpClient.DownloadStream("./" & CType(AListing(i), TElSftpFileInfo).Name, stream, SBTypes.TSBFileTransferMode.ftmOverwrite)

' the stream object now contains the contents of the file

Posted: 09/19/2015 07:16:02
by Philipp Bundschuh (Basic support level)
Joined: 09/18/2015
Posts: 5

Thanks Ken, helped me.



Topic viewed 2009 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!