<p>** Added Issue as status PROPOSED type FEATURE **</p>
<p>This is a discussion thread.</p>
<p> </p>
<p>Is there any interest in including a way to expose current transfer progress to an application?</p>
<p> </p>
<p>For example, imagine a user wanting to upload a file could pass in an implementation of:</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>public interface IFileTransferHandler</p>
<p>{</p>
<p> ulong BytesRead { get; }</p>
<p> </p>
<p> void IncrementBytesRead(ulong bytes);</p>
<p> </p>
<p> void TransferCompleted();</p>
<p>}</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>Whenever the callback for Write returns confirming that the bytes were written, IncrementReadBytes would be called and whenever the file is fully uploaded TransferCompleted gets called. Since we're passing in streams, there's no objective way to determine</p>
<p> the file size so that would have to be provided in the implementation, if at all.</p>
<p> </p>
<p>All you really need to do is add a field for that interface in SftpFileStream and then pass it to all calls to RequestWrite and then create some new constructors so that the interface can be passed along from the publicly exposed methods (I've managed to</p>
<p> build a sample implementation for sftp upload, so this method works). The only issue is if the handler throws an exception. Since it's asynchronous the debugger displays the stack trace in the wrong place and could confuse developers.</p>
Comments: ** Comment from web user: olegkap **
<p>This is a discussion thread.</p>
<p> </p>
<p>Is there any interest in including a way to expose current transfer progress to an application?</p>
<p> </p>
<p>For example, imagine a user wanting to upload a file could pass in an implementation of:</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>public interface IFileTransferHandler</p>
<p>{</p>
<p> ulong BytesRead { get; }</p>
<p> </p>
<p> void IncrementBytesRead(ulong bytes);</p>
<p> </p>
<p> void TransferCompleted();</p>
<p>}</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>Whenever the callback for Write returns confirming that the bytes were written, IncrementReadBytes would be called and whenever the file is fully uploaded TransferCompleted gets called. Since we're passing in streams, there's no objective way to determine</p>
<p> the file size so that would have to be provided in the implementation, if at all.</p>
<p> </p>
<p>All you really need to do is add a field for that interface in SftpFileStream and then pass it to all calls to RequestWrite and then create some new constructors so that the interface can be passed along from the publicly exposed methods (I've managed to</p>
<p> build a sample implementation for sftp upload, so this method works). The only issue is if the handler throws an exception. Since it's asynchronous the debugger displays the stack trace in the wrong place and could confuse developers.</p>
Comments: ** Comment from web user: olegkap **
Hi,
I just checked in a code where I added few callback functions which are called based on progress.
Now UploadFile, DownloadFile and ListDirectory will have extra optional callback parameter which can be a function to report progress.
Here is code example that I used to test it:
sftp.UploadFile(File.OpenRead(@"D:\aaaaa.csv"), "test.mpg", (count) => {
Console.WriteLine(count);
});
Please let me know if you need any other parameters to be reported.
Thanks,
Oleg