@@ -584,7 +584,7 @@ public IEnumerable<ISftpFile> ListDirectory(string path, Action<int> listCallbac
584
584
{
585
585
CheckDisposed ( ) ;
586
586
587
- return InternalListDirectory ( path , listCallback ) ;
587
+ return InternalListDirectory ( path , asyncResult : null , listCallback ) ;
588
588
}
589
589
590
590
#if FEATURE_ASYNC_ENUMERABLE
@@ -669,12 +669,7 @@ public IAsyncResult BeginListDirectory(string path, AsyncCallback asyncCallback,
669
669
{
670
670
try
671
671
{
672
- var result = InternalListDirectory ( path , count =>
673
- {
674
- asyncResult . Update ( count ) ;
675
-
676
- listCallback ? . Invoke ( count ) ;
677
- } ) ;
672
+ var result = InternalListDirectory ( path , asyncResult , listCallback ) ;
678
673
679
674
asyncResult . SetAsCompleted ( result , completedSynchronously : false ) ;
680
675
}
@@ -899,12 +894,7 @@ public IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback
899
894
{
900
895
try
901
896
{
902
- InternalDownloadFile ( path , output , asyncResult , offset =>
903
- {
904
- asyncResult . Update ( offset ) ;
905
-
906
- downloadCallback ? . Invoke ( offset ) ;
907
- } ) ;
897
+ InternalDownloadFile ( path , output , asyncResult , downloadCallback ) ;
908
898
909
899
asyncResult . SetAsCompleted ( exception : null , completedSynchronously : false ) ;
910
900
}
@@ -1132,11 +1122,7 @@ public IAsyncResult BeginUploadFile(Stream input, string path, bool canOverride,
1132
1122
{
1133
1123
try
1134
1124
{
1135
- InternalUploadFile ( input , path , flags , asyncResult , offset =>
1136
- {
1137
- asyncResult . Update ( offset ) ;
1138
- uploadCallback ? . Invoke ( offset ) ;
1139
- } ) ;
1125
+ InternalUploadFile ( input , path , flags , asyncResult , uploadCallback ) ;
1140
1126
1141
1127
asyncResult . SetAsCompleted ( exception : null , completedSynchronously : false ) ;
1142
1128
}
@@ -2200,7 +2186,7 @@ private IEnumerable<FileInfo> InternalSynchronizeDirectories(string sourcePath,
2200
2186
2201
2187
#region Existing Files at The Destination
2202
2188
2203
- var destFiles = InternalListDirectory ( destinationPath , listCallback : null ) ;
2189
+ var destFiles = InternalListDirectory ( destinationPath , asyncResult : null , listCallback : null ) ;
2204
2190
var destDict = new Dictionary < string , ISftpFile > ( ) ;
2205
2191
foreach ( var destFile in destFiles )
2206
2192
{
@@ -2267,13 +2253,14 @@ private IEnumerable<FileInfo> InternalSynchronizeDirectories(string sourcePath,
2267
2253
/// Internals the list directory.
2268
2254
/// </summary>
2269
2255
/// <param name="path">The path.</param>
2256
+ /// <param name="asyncResult">An <see cref="IAsyncResult"/> that references the asynchronous request.</param>
2270
2257
/// <param name="listCallback">The list callback.</param>
2271
2258
/// <returns>
2272
2259
/// A list of files in the specfied directory.
2273
2260
/// </returns>
2274
2261
/// <exception cref="ArgumentNullException"><paramref name="path" /> is <b>null</b>.</exception>
2275
2262
/// <exception cref="SshConnectionException">Client not connected.</exception>
2276
- private IEnumerable < ISftpFile > InternalListDirectory ( string path , Action < int > listCallback )
2263
+ private IEnumerable < ISftpFile > InternalListDirectory ( string path , SftpListDirectoryAsyncResult asyncResult , Action < int > listCallback )
2277
2264
{
2278
2265
if ( path is null )
2279
2266
{
@@ -2309,6 +2296,8 @@ private IEnumerable<ISftpFile> InternalListDirectory(string path, Action<int> li
2309
2296
f . Value ) ) ;
2310
2297
}
2311
2298
2299
+ asyncResult ? . Update ( result . Count ) ;
2300
+
2312
2301
// Call callback to report number of files read
2313
2302
if ( listCallback is not null )
2314
2303
{
@@ -2375,6 +2364,8 @@ private void InternalDownloadFile(string path, Stream output, SftpDownloadAsyncR
2375
2364
2376
2365
totalBytesRead += ( ulong ) data . Length ;
2377
2366
2367
+ asyncResult ? . Update ( totalBytesRead ) ;
2368
+
2378
2369
if ( downloadCallback is not null )
2379
2370
{
2380
2371
// copy offset to ensure it's not modified between now and execution of callback
@@ -2447,6 +2438,8 @@ private void InternalUploadFile(Stream input, string path, Flags flags, SftpUplo
2447
2438
_ = Interlocked . Decrement ( ref expectedResponses ) ;
2448
2439
_ = responseReceivedWaitHandle . Set ( ) ;
2449
2440
2441
+ asyncResult ? . Update ( writtenBytes ) ;
2442
+
2450
2443
// Call callback to report number of bytes written
2451
2444
if ( uploadCallback is not null )
2452
2445
{
0 commit comments