robinrodricks / FluentFTP.GnuTLS

Premiere .NET wrapper for GnuTLS along with integration into FluentFTP
GNU Lesser General Public License v2.1
4 stars 5 forks source link

Download with Progress throws exception #131

Closed crobibero closed 7 months ago

crobibero commented 7 months ago

While attempting to debug connection issues I came across the following exception. After removing the progress parameter the exception isn't thrown.

var downloadProgress = new Progress<FtpProgress>(p =>
{
    var progress = (int)p.Progress;
    if (progress % 10 == 0)
    {
        _logger.LogInformation(
            "Progress: {Progress:F1}% ETA: {Eta}",
            p.Progress,
            p.ETA);
    }
});

var client = new AsyncFtpClient(host, username, password);
client.Config.CustomStream = typeof(GnuTlsStream);
await client.AutoConnect(cancellationToken).ConfigureAwait(false);
var downloadStatus = await client.DownloadFile(
        fileDestinationPath,
        normalizedFilePath,
        verifyOptions: FtpVerify.OnlyChecksum | FtpVerify.Retry | FtpVerify.Delete,
        progress: downloadProgress,
        token: cancellationToken)
    .ConfigureAwait(false);

Exception:

FluentFTP.Exceptions.FtpException: Error while downloading the file from the server. See InnerException for more info.
 ---> System.ArgumentException: GnuTlsInternalStream.Read: maxCount must be greater than zero
   at FluentFTP.GnuTLS.GnuTlsInternalStream.Read(Byte[] buffer, Int32 offset, Int32 maxCount)
   at System.IO.Stream.<>c.<BeginReadInternal>b__38_0(Object <p0>)
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at FluentFTP.FtpSocketStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken token)
   at FluentFTP.FtpDataStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken token)
   at FluentFTP.AsyncFtpClient.DownloadFileInternalAsync(String localPath, String remotePath, Stream outStream, Int64 restartPosition, IProgress`1 progress, CancellationToken token, FtpProgress metaProgress, Int64 knownFileSize, Boolean isAppend, Int64 stopPosition)
   --- End of inner exception stack trace ---
   at FluentFTP.AsyncFtpClient.DownloadFileInternalAsync(String localPath, String remotePath, Stream outStream, Int64 restartPosition, IProgress`1 progress, CancellationToken token, FtpProgress metaProgress, Int64 knownFileSize, Boolean isAppend, Int64 stopPosition)
   at FluentFTP.AsyncFtpClient.DownloadFileToFileAsync(String localPath, String remotePath, FtpLocalExists existsMode, FtpVerify verifyOptions, IProgress`1 progress, CancellationToken token, FtpProgress metaProgress)
   at FluentFTP.AsyncFtpClient.DownloadFile(String localPath, String remotePath, FtpLocalExists existsMode, FtpVerify verifyOptions, IProgress`1 progress, CancellationToken token)
FanDjango commented 7 months ago

I will investigate this further

FanDjango commented 7 months ago

I believe it is a victim of the problems with progress reporting code that has been fixed today:

Please see https://github.com/robinrodricks/FluentFTP/pull/1519 and https://github.com/robinrodricks/FluentFTP/issues/1518

Try the absolute newest current master - it should be better

crobibero commented 7 months ago

Ah my mistake- the issue only occurred for me when using GnuTlsStream so I made that assumption!

Referencing a dll build on current master https://github.com/robinrodricks/FluentFTP/commit/fb2ee75f08929685bf5cfd9447d5343c3ffc7fc6 I get the same issue. I will close this and reopen in the correct repo

FanDjango commented 7 months ago

Ok, waiting for that