EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Download a file

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#18893
Posted: 02/01/2012 08:34:08
by Eugene Mayevski (EldoS Corp.)

SendKeepAlive is present in SSH client and in TElSimpleSSHClient. It's not exposed in TElSimpleSFTPClient.


Sincerely yours
Eugene Mayevski
#18898
Posted: 02/01/2012 10:51:21
by sean rogers (Basic support level)
Joined: 02/01/2012
Posts: 5

Hi,

I didnt get an error reported with the DownloadStream - it still just hung.


But I have managed to download the two big files I had by following the FileOpen/Read/CloseHandle pattern.

Here is my code that worked:



public string ReadFile(string source)
{

Check.RequireNotNullOrEmpty(() => source);

byte[] handle = null;
try
{
var buffer = new byte[BufferSize];
var charsReadSoFar = 0;

handle = Client.OpenFile(source, (int) FileOpenModeType.Read, (int) FileOpenAccessType.ReadLock, null);

using (var memoryStream = new MemoryStream())
{
var charsRead = ReadChunkFromFile(memoryStream, handle, ref charsReadSoFar, buffer);
while (charsRead == BufferSize)
{
charsRead = ReadChunkFromFile(memoryStream, handle, ref charsReadSoFar, buffer);
}

memoryStream.Position = 0;

var document = new XmlDocument();
document.Load(memoryStream);
return document.OuterXml;
}
}
finally
{
Client.CloseHandle(handle);
Client.Close(true);
}
}

private int ReadChunkFromFile(Stream memoryStream, byte[] handle, ref int charsReadSoFar, byte[] buffer)
{
var charsRead = Client.Read(handle, charsReadSoFar, ref buffer, BufferSize);
charsReadSoFar = charsReadSoFar + charsRead;
memoryStream.Write(buffer, 0, charsRead);
memoryStream.Flush();
return charsRead;
}


Thanks for your help.

Sean

Reply

Statistics

Topic viewed 2053 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!