@@ -583,7 +583,7 @@ public IEnumerable<ISftpFile> ListDirectory(string path, Action<int> listCallbac
583
583
{
584
584
CheckDisposed ( ) ;
585
585
586
- return InternalListDirectory ( path , listCallback ) ;
586
+ return InternalListDirectory ( path , asyncResult : null , listCallback ) ;
587
587
}
588
588
589
589
/// <summary>
@@ -666,12 +666,7 @@ public IAsyncResult BeginListDirectory(string path, AsyncCallback asyncCallback,
666
666
{
667
667
try
668
668
{
669
- var result = InternalListDirectory ( path , count =>
670
- {
671
- asyncResult . Update ( count ) ;
672
-
673
- listCallback ? . Invoke ( count ) ;
674
- } ) ;
669
+ var result = InternalListDirectory ( path , asyncResult , listCallback ) ;
675
670
676
671
asyncResult . SetAsCompleted ( result , completedSynchronously : false ) ;
677
672
}
@@ -898,12 +893,7 @@ public IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback
898
893
{
899
894
try
900
895
{
901
- InternalDownloadFile ( path , output , asyncResult , offset =>
902
- {
903
- asyncResult . Update ( offset ) ;
904
-
905
- downloadCallback ? . Invoke ( offset ) ;
906
- } ) ;
896
+ InternalDownloadFile ( path , output , asyncResult , downloadCallback ) ;
907
897
908
898
asyncResult . SetAsCompleted ( exception : null , completedSynchronously : false ) ;
909
899
}
@@ -1131,11 +1121,7 @@ public IAsyncResult BeginUploadFile(Stream input, string path, bool canOverride,
1131
1121
{
1132
1122
try
1133
1123
{
1134
- InternalUploadFile ( input , path , flags , asyncResult , offset =>
1135
- {
1136
- asyncResult . Update ( offset ) ;
1137
- uploadCallback ? . Invoke ( offset ) ;
1138
- } ) ;
1124
+ InternalUploadFile ( input , path , flags , asyncResult , uploadCallback ) ;
1139
1125
1140
1126
asyncResult . SetAsCompleted ( exception : null , completedSynchronously : false ) ;
1141
1127
}
@@ -2200,7 +2186,7 @@ private List<FileInfo> InternalSynchronizeDirectories(string sourcePath, string
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
{
@@ -2268,13 +2254,14 @@ private List<FileInfo> InternalSynchronizeDirectories(string sourcePath, string
2268
2254
/// Internals the list directory.
2269
2255
/// </summary>
2270
2256
/// <param name="path">The path.</param>
2257
+ /// <param name="asyncResult">An <see cref="IAsyncResult"/> that references the asynchronous request.</param>
2271
2258
/// <param name="listCallback">The list callback.</param>
2272
2259
/// <returns>
2273
2260
/// A list of files in the specfied directory.
2274
2261
/// </returns>
2275
2262
/// <exception cref="ArgumentNullException"><paramref name="path" /> is <see langword="null"/>.</exception>
2276
2263
/// <exception cref="SshConnectionException">Client not connected.</exception>
2277
- private List < ISftpFile > InternalListDirectory ( string path , Action < int > listCallback )
2264
+ private List < ISftpFile > InternalListDirectory ( string path , SftpListDirectoryAsyncResult asyncResult , Action < int > listCallback )
2278
2265
{
2279
2266
if ( path is null )
2280
2267
{
@@ -2314,6 +2301,8 @@ private List<ISftpFile> InternalListDirectory(string path, Action<int> listCallb
2314
2301
f . Value ) ) ;
2315
2302
}
2316
2303
2304
+ asyncResult ? . Update ( result . Count ) ;
2305
+
2317
2306
// Call callback to report number of files read
2318
2307
if ( listCallback is not null )
2319
2308
{
@@ -2380,6 +2369,8 @@ private void InternalDownloadFile(string path, Stream output, SftpDownloadAsyncR
2380
2369
2381
2370
totalBytesRead += ( ulong ) data . Length ;
2382
2371
2372
+ asyncResult ? . Update ( totalBytesRead ) ;
2373
+
2383
2374
if ( downloadCallback is not null )
2384
2375
{
2385
2376
// Copy offset to ensure it's not modified between now and execution of callback
@@ -2452,6 +2443,8 @@ private void InternalUploadFile(Stream input, string path, Flags flags, SftpUplo
2452
2443
_ = Interlocked . Decrement ( ref expectedResponses ) ;
2453
2444
_ = responseReceivedWaitHandle . Set ( ) ;
2454
2445
2446
+ asyncResult ? . Update ( writtenBytes ) ;
2447
+
2455
2448
// Call callback to report number of bytes written
2456
2449
if ( uploadCallback is not null )
2457
2450
{
0 commit comments