Skip to content

Reconnect throwing error #1770

@RohanSingh-Raik

Description

@RohanSingh-Raik

In my code I am creating new ftp client every operation

try
{
using FtpClient conn = new(_ftpAuthConfig.Host, _ftpAuthConfig.UserName, _ftpAuthConfig.Password);
conn.Logger = new FtpLogAdapter(_logger);
conn.Connect();
conn.UploadBytes(data, Path.Combine(uploadFolderPath, fileName));
_logger.LogDebug("FTP: {fileName} uploaded to {folderPath}", fileName, uploadFolderPath);
}
catch (Exception ex)
{
_logger.LogError(ex, "FTP: Server Upload Error");
throw;
}


But occasionally ftpfluent throws a warning reconnect needed due to stale data present on the control connection and after which it tries to reconnect and throws this error:
FluentFTP.Exceptions.FtpException: Error while uploading the file to the server. See InnerException for more info. ---> System.AggregateException: Additional error occured while trying to resume uploading the file '/IN/5973_r3.xml' at position 131072 (Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..) (You cannot modify the position of a FtpDataStream. This property is updated as data is read or written to the stream.) ---> System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.. ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host. at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 count) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 count) at FluentFTP.FtpClient.UploadFileInternal(Stream fileData, String localPath, String remotePath, Boolean createRemoteDir, FtpRemoteExists existsMode, Boolean fileExists, Boolean fileExistsKnown, Action`1 progress, FtpProgress metaProgress) --- End of inner exception stack trace --- at FluentFTP.FtpClient.ResumeUpload(String remotePath, Stream& upStream, Int64 remotePosition, IOException ex) at FluentFTP.FtpClient.UploadFileInternal(Stream fileData, String localPath, String remotePath, Boolean createRemoteDir, FtpRemoteExists existsMode, Boolean fileExists, Boolean fileExistsKnown, Action`1 progress, FtpProgress metaProgress) ---> (Inner Exception #1) System.InvalidOperationException: You cannot modify the position of a FtpDataStream. This property is updated as data is read or written to the stream. at FluentFTP.FtpDataStream.set_Position(Int64 value) at FluentFTP.FtpClient.ResumeUpload(String remotePath, Stream& upStream, Int64 remotePosition, IOException ex)<--- --- End of inner exception stack trace --- at FluentFTP.FtpClient.UploadFileInternal(Stream fileData, String localPath, String remotePath, Boolean createRemoteDir, FtpRemoteExists existsMode, Boolean fileExists, Boolean fileExistsKnown, Action`1 progress, FtpProgress metaProgress) at FluentFTP.FtpClient.UploadBytes(Byte[] fileData, String remotePath, FtpRemoteExists existsMode, Boolean createRemoteDir, Action`1 progress)
Why is reconnection required when I am using new connection every operation and the size of files being uploaded is very less like 60kb.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions