FluentFTP icon indicating copy to clipboard operation
FluentFTP copied to clipboard

calling UploadFile for large file got exception with message "You cannot modify the position of a FtpDataStream. This property is updated as data is read or written to the stream."

Open amidofu opened this issue 7 years ago • 13 comments
trafficstars

FTP OS: not sure, probably Unix, the server is provided by GoDaddy: https://en.wikipedia.org/wiki/GoDaddy

FTP Server: not sure

Computer OS: ? Windows 7

<write details about your bug report / feature request here> I try to upload a big file (about 1.5GB) by FtpClient.UploadFile, but it always throws exception with the message: "You cannot modify the position of a FtpDataStream. This property is updated as data is read or written to the stream." Tried to use FileZilla to upload such large file and it worked fine.

Small files can be uploaded (tried with files that are less than 500KB) normally by FtpClient.UploadFile

Logs :

fluent_ftp_log_file.txt

<paste logs here but DO NOT delete the lines above and below this line>

amidofu avatar Mar 23 '18 09:03 amidofu

Sounds like a part of our uploading implementation is not supported by your server. We'll have to modify it accordingly.

robinrodricks avatar Apr 07 '18 06:04 robinrodricks

I have encountered the same problem using a FileZilla server.

CHMaagaard avatar Apr 24 '18 06:04 CHMaagaard

I have too, In my case the server had run out of disk space.

klesteb avatar Jun 25 '18 21:06 klesteb

Does this library return the 4xx codes in case of transient negative completions? I am encountering an issue where the upstream server has run out of disk but I am getting a generic error message

"You cannot modify the position of a FtpDataStream. This property is updated as data is read or written to the stream"

Is this bug being actively worked upon?

sanjitmisra avatar Feb 25 '19 10:02 sanjitmisra

Hi, no this bug is not actively being worked upon. We have insufficient info to fix something. You are free to submit a PR or help us understand how to send specialised 4xx code.

On Mon, Feb 25, 2019, 3:30 PM S.M. <[email protected] wrote:

Does this library return the 4xx codes in case of transient negative completions? I am encountering an issue where the upstream server has run out of disk but I am getting a generic error message

"You cannot modify the position of a FtpDataStream. This property is updated as data is read or written to the stream"

Is this bug being actively worked upon?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/robinrodricks/FluentFTP/issues/283#issuecomment-466949724, or mute the thread https://github.com/notifications/unsubscribe-auth/AGe6KgBkzNbpjrOf0CNLpvC1t0Mk6txoks5vQ7QwgaJpZM4S4X5p .

robinrodricks avatar Feb 25 '19 10:02 robinrodricks

I too am encountering this issue while being connected to FileZilla Server, but the error is not limited to just that server. It doesn't happen all the time, but I have tracked down the top-level reason.

FluentFTP/Client/FtpClient_HighLevelUpload.cs line 1003 shows

							upStream = OpenAppend(remotePath, UploadDataType, true);
							upStream.Position = offset;

OpenAppend (FluentFTP/Client/FtpClient_LowLevel.cs line 1526) in turn calls OpenDataStream (FluentFTP/Client/FtpClient_LowLevel.cs line 810) which in turn calls OpenPassiveDataStream (FluentFTP/Client/FtpClient_LowLevel.cs line 306) or OpenActiveDataStream (FluentFTP/Client/FtpClient_LowLevel.cs line 578). Both OpenPassiveDataStream and OpenActiveDataStream return FtpDataStream instances.

/FluentFTP/Stream/FtpDataStream.cs line 54 shows

public override long Position {
			get => m_position;
			set => throw new InvalidOperationException("You cannot modify the position of a FtpDataStream. This property is updated as data is read or written to the stream.");
		}

This error occurs only when a socket error of 10054 occurring during a resumed upload. (FluentFTP/Client/FtpClient_HighLevelUpload.cs line 994).

Trox085 avatar Aug 13 '19 20:08 Trox085

I agree, this error is not down to a particular server but in the way the code tries to resume any download. The ResumeDownload methods (standard and Async) both try to set the position of the stream, but as noted by Trox085, the setter for Position in FtpDataStream throws an exception. Maybe the answer is to do a read up to the point where you want to resume from?

AdamCWray avatar Oct 14 '19 15:10 AdamCWray

We are having the same issues with a C# FTP Server: https://github.com/FubarDevelopment/FtpServer

So it does not seem to be a server specific problem.

Any ideas?

zmarty avatar Oct 17 '19 16:10 zmarty

I have found that some Windows based FTP servers drop the connection when the transfer reaches 3GB. This is for both uploads and downloads. I have a fix at: https://github.com/klesteb/XAS-csharp/blob/master/Network/FTP/Client.cs

klesteb avatar Nov 25 '19 23:11 klesteb

I have the exact same issue with a file 75,3 mb, tried with the latest version 32.4.3.

Peter-Optiway avatar Jun 29 '20 15:06 Peter-Optiway

Same issue for me with a Filezilla Server. The transferred file is only 900kb big!

animha avatar Jul 20 '20 07:07 animha

Hi,

I'm using the current nuget version 33.0.3. but I'm still running into the above problem when trying to upload a 2GB File via Upload File Async. Does this version contain the above fix ?

Here is the Stacktrace (partly in German)

Error while uploading the file to the server. See InnerException for more info. bei FluentFTP.FtpClient.<UploadFileInternalAsync>d__116.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei FluentFTP.FtpClient.<UploadFileFromFileAsync>d__110.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei FluentFTP.FtpClient.<UploadFileAsync>d__109.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() bei Lorenz.dobVeevaAccess.VeevaFtpStagingServer.<UploadSubmissionArchive>d__11.MoveNext() You cannot modify the position of a FtpDataStream. This property is updated as data is read or written to the stream. bei FluentFTP.FtpDataStream.set_Position(Int64 value) bei FluentFTP.FtpClient.<ResumeUploadAsync>d__118.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei FluentFTP.FtpClient.<UploadFileInternalAsync>d__116.MoveNext()

Best Regards and thank you

Peter

kickerskopp avatar Jan 31 '21 17:01 kickerskopp

Same problem with FileZilla. FluentFTP version 33.1.6.

I'm taking my code from this example using (Stream ostream = conn.OpenAppend("/full/or/relative/path/to/file")) { try { ostream.Position = ostream.Length; var sr = new StreamWriter(ostream); sr.WriteLine(...); } finally { ostream.Close(); } } given here https://github.com/robinrodricks/FluentFTP/issues/52

System.InvalidOperationException HResult=0x80131509 Message=You cannot modify the position of a FtpDataStream. This property is updated as data is read or written to the stream. Source=FluentFTP StackTrace: at FluentFTP.FtpDataStream.set_Position(Int64 value) at VWUK.Utils.FtpService.FtpService.AppendMode(FtpClient ftp, String path, String data) in

hrafnkel avatar Apr 20 '21 10:04 hrafnkel

@hrafnkel See: https://github.com/robinrodricks/FluentFTP/issues/711#issuecomment-1333559332

@AdamCWray

I agree, this error is not down to a particular server but in the way the code tries to resume any download. The ResumeDownload methods (standard and Async) both try to set the position of the stream, but as noted by Trox085, the setter for Position in FtpDataStream throws an exception. Maybe the answer is to do a read up to the point where you want to resume from?

Not down to a particular server. Correct. The rest is fixed by now.

FanDjango avatar Dec 01 '22 11:12 FanDjango