EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Download file via sftp to string

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#34504
Posted: 09/18/2015 17:50:17
by Philipp Bundschuh (Basic support level)
Joined: 09/18/2015
Posts: 5

Hello,
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?

Regards
Philipp
#34505
Posted: 09/18/2015 18:13:34
by Ken Ivanov (EldoS Corp.)

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).

Ken
#34506
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?

regards
Philipp
#34507
Posted: 09/18/2015 18:57:55
by Ken Ivanov (EldoS Corp.)

Philipp,

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

Code
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


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

Thanks Ken, helped me.
regards
Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.

Reply

Statistics

Topic viewed 1682 times

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




|

Back to top

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

Got it!