@@ -28,7 +28,6 @@ public class SftpFileStream : Stream
28
28
private bool _canRead ;
29
29
private bool _canSeek ;
30
30
private bool _canWrite ;
31
- private ulong _serverFilePosition ;
32
31
33
32
private readonly object _lock = new object ( ) ;
34
33
@@ -262,7 +261,6 @@ internal SftpFileStream(ISftpSession session, string path, FileMode mode, FileAc
262
261
{
263
262
var attributes = _session . RequestFStat ( _handle , false ) ;
264
263
_position = attributes . Size ;
265
- _serverFilePosition = ( ulong ) attributes . Size ;
266
264
}
267
265
}
268
266
@@ -347,9 +345,6 @@ public override int Read(byte[] buffer, int offset, int count)
347
345
348
346
var data = _session . RequestRead ( _handle , ( ulong ) _position , ( uint ) _readBufferSize ) ;
349
347
350
- // TODO: don't we need to take into account the number of bytes read (data.Length) ?
351
- _serverFilePosition = ( ulong ) _position ;
352
-
353
348
if ( data . Length == 0 )
354
349
{
355
350
break ;
@@ -422,11 +417,11 @@ public override int ReadByte()
422
417
if ( _bufferPosition >= _bufferLen )
423
418
{
424
419
_bufferPosition = 0 ;
420
+ _bufferLen = 0 ;
425
421
426
422
var data = _session . RequestRead ( _handle , ( ulong ) _position , ( uint ) _readBufferSize ) ;
427
423
428
424
_bufferLen = data . Length ;
429
- _serverFilePosition = ( ulong ) _position ;
430
425
431
426
if ( _bufferLen == 0 )
432
427
{
@@ -501,7 +496,6 @@ public override long Seek(long offset, SeekOrigin origin)
501
496
throw new EndOfStreamException ( "End of stream." ) ;
502
497
}
503
498
_position = newPosn ;
504
- _serverFilePosition = ( ulong ) newPosn ;
505
499
}
506
500
else
507
501
{
@@ -645,8 +639,7 @@ public override void Write(byte[] buffer, int offset, int count)
645
639
{
646
640
using ( var wait = new AutoResetEvent ( false ) )
647
641
{
648
- _session . RequestWrite ( _handle , _serverFilePosition , buffer , offset , tempLen , wait ) ;
649
- _serverFilePosition += ( ulong ) tempLen ;
642
+ _session . RequestWrite ( _handle , ( ulong ) _position , buffer , offset , tempLen , wait ) ;
650
643
}
651
644
}
652
645
else
@@ -668,8 +661,7 @@ public override void Write(byte[] buffer, int offset, int count)
668
661
{
669
662
using ( var wait = new AutoResetEvent ( false ) )
670
663
{
671
- _session . RequestWrite ( _handle , _serverFilePosition , _writeBuffer , 0 , _bufferPosition , wait ) ;
672
- _serverFilePosition += ( ulong ) _bufferPosition ;
664
+ _session . RequestWrite ( _handle , ( ulong ) ( _position - _bufferPosition ) , _writeBuffer , 0 , _bufferPosition , wait ) ;
673
665
}
674
666
675
667
_bufferPosition = 0 ;
@@ -699,8 +691,7 @@ public override void WriteByte(byte value)
699
691
{
700
692
using ( var wait = new AutoResetEvent ( false ) )
701
693
{
702
- _session . RequestWrite ( _handle , _serverFilePosition , _writeBuffer , 0 , _bufferPosition , wait ) ;
703
- _serverFilePosition += ( ulong ) _bufferPosition ;
694
+ _session . RequestWrite ( _handle , ( ulong ) ( _position - _bufferPosition ) , _writeBuffer , 0 , _bufferPosition , wait ) ;
704
695
}
705
696
706
697
_bufferPosition = 0 ;
@@ -779,8 +770,7 @@ private void FlushWriteBuffer()
779
770
{
780
771
using ( var wait = new AutoResetEvent ( false ) )
781
772
{
782
- _session . RequestWrite ( _handle , _serverFilePosition , _writeBuffer , 0 , _bufferPosition , wait ) ;
783
- _serverFilePosition += ( ulong ) _bufferPosition ;
773
+ _session . RequestWrite ( _handle , ( ulong ) ( _position - _bufferPosition ) , _writeBuffer , 0 , _bufferPosition , wait ) ;
784
774
}
785
775
786
776
_bufferPosition = 0 ;
0 commit comments