Skip to content

SSH.SFTPTransferQueue

Andrew Lambert edited this page Dec 5, 2022 · 14 revisions

SSH.SFTPTransferQueue

Class Declaration

 Protected Class SFTPTransferQueue

Remarks

This class performs several parallel transfers over SFTP. Using this class instead of performing the transfers one after the other helps to mitigate the speed bottleneck imposed by SFTP's per-packet acknowledgement and maximum packet size. By sending a small number of packets at a time per transfer, the time spent waiting for the first transfer to receive an acknowledgement can be utilized by the second, third, etc. transfers. If enough transfers are enqueued then by the time we cycle back around to the first transfer it will be ready again.

Create a new instance of this class and then add transfers by calling the AddDownload() or AddUpload() methods.

Adding a transfer does not immediately begin transferring the file. For that you need to call the PerformOnce() method. PerformOnce() performs a little bit of each transfer on each call, raising the Progress() event for each one. If a transfer finishes then the TransferComplete() event is raised.

PerformOnce() will return True if there are any unfinished transfers remaining. Keep calling it until it returns False.

If AutoClose=True (the default) then both the remote SFTPStream and the local BinaryStream will have their Close() methods called automatically. If AutoClose=False then you must be sure to close the streams yourself at some point, typically in the TransferComplete() event.

Once a transfer completes and its TransferComplete() event returns it is automatically removed from the queue. You may also remove a transfer at any time by calling the RemoveTransfer() method. Removing a transfer effectively pauses it, and you may resume it by re-adding it to the queue.

While the SFTP protocol technically allows up to 232 simultaneous transfers, very few, if any, actual SFTP servers will allow you to open more than a few hundred at a time. In addition the local system may limit the number of files your app can have open at once. The MaxCount property sets the maximum number of transfers the SFTPTransferQueue will allow at any one time. AddDownload() and AddUpload() will raise an exception if adding the transfer would exceed this limit.

PacketCount sets the maximum number of 32KB packets that each up/download will be allowed to transfer per call to PerformOnce(). Setting a large PacketCount will not improve transfer speeds, and may actually seriously slow it down. The default is 1 packet.

Event definitions

Methods

Properties

See also

Clone this wiki locally