EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Understanding TElSftpClient.AutoAdjustTransferBlock

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#7524
Posted: 09/04/2008 23:10:38
by Charles DeWeese (Standard support level)
Joined: 04/17/2008
Posts: 52


If I set TElSftpClient.AutoAdjustTransferBlock to true and use a block size of 262144 the uploaded file is corrupted.

Take the sample project SophisticatedClient

Changing FILE_BLOCK_SIZE to 262144 and setting AutoAdjustTransferBlock results in corruption.

BlockRead(CurrentFile, Buf[0], FILE_BLOCK_SIZE, Transferred);
SftpClient.Write(CurrentHandle, CurrentFileOffset, @Buf[0], Transferred);

Is there a specific reason why the corruption occurs or is this a bug?
#7526
Posted: 09/05/2008 04:45:25
by Ken Ivanov (EldoS Corp.)

Most likely, the server does not support pipelining correctly. Did you have a chance to check if the issue does occur with either FILE_BLOCK_SIZE set to 262144 or AutoAdjustTransferBlock set to true (but not the both)?
#7527
Posted: 09/05/2008 04:45:53
by Ken Ivanov (EldoS Corp.)

BTW, does the issue occur with some particular server or with any server you are connecting to?
#7528
Posted: 09/05/2008 05:33:23
by Charles DeWeese (Standard support level)
Joined: 04/17/2008
Posts: 52

Yes, if AutoAdjustTransferBlock is false or if FILE_BLOCK_SIZE is smaller the corruption doesn't occur. I tested with 65536 and 131072 and those worked.

That combination causes problems with all the sftp servers I have available to me for testing, Multiple versions of OpenSSH and a couple windows based servers.
#7531
Posted: 09/05/2008 11:18:19
by Ken Ivanov (EldoS Corp.)

Got it. It is the demo application who leads to the issue.

The asynchronous TElSFTPClient.Write() method expects the passed buffer to exist until either OnSuccess or OnError event is fired. However, as Buf is a local variable, it is destroyed once the WriteNextBlockToFile() method returns. That's why you get the corrupted file on the remote side.

A quick fix is to move the Buf array outside the scope of the WriteNextBlockToFile() method (e.g. to the make it a field of TForm1 class).

Thank you for reporting the issue. We will introduce the necessary changes to the demo application.
#7532
Posted: 09/05/2008 15:27:50
by Charles DeWeese (Standard support level)
Joined: 04/17/2008
Posts: 52

Thanks for the update.

I also realized that having TElSFTPClient.SBB3Compatible set to false results in a new problem because TElSFTPClient.OnSuccess is fired early before the buffer is completely sent.

Perhaps there should be some additional documentation stating this, because its not all that obvious.

Designing a new application it seemed to make sense to set SBB3Compatible to false.
#7537
Posted: 09/08/2008 00:59:03
by Ken Ivanov (EldoS Corp.)

Quote
I also realized that having TElSFTPClient.SBB3Compatible set to false results in a new problem because TElSFTPClient.OnSuccess is fired early before the buffer is completely sent.

Yes, that's how it was designed. Thank you for reporting the documentation issue, we will fix it as soon as possible.

Quote
Designing a new application it seemed to make sense to set SBB3Compatible to false.

Please consider using TElSimpleSFTPClient implementation as a guide -- it internally uses TElSFTPClient with SBB3Compatible property set to false.
Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.

Reply

Statistics

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