File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -168,9 +168,14 @@ Future<void> _download(
168168 final dlWatch = Stopwatch ()..start ();
169169 Loggers .app.info ('SFTP download start size=$size ' );
170170
171+ final timeout = Duration (
172+ seconds: req.timeoutSeconds <= 0 ? 60 : req.timeoutSeconds,
173+ );
174+
171175 while (offset < size) {
172176 final remaining = size - offset;
173177 final length = remaining < segmentSize ? remaining : segmentSize;
178+ var segmentBytes = 0 ;
174179
175180 try {
176181 await for (final chunk
@@ -181,8 +186,9 @@ Future<void> _download(
181186 chunkSize: _sftpDownloadChunkSize,
182187 maxPendingRequests: _sftpDownloadMaxPendingRequests,
183188 )
184- .timeout (Duration (seconds : 30 ) )) {
189+ .timeout (timeout )) {
185190 localFile.add (chunk);
191+ segmentBytes += chunk.length;
186192 totalBytes += chunk.length;
187193 chunkCount++ ;
188194
@@ -198,7 +204,13 @@ Future<void> _download(
198204 } on TimeoutException {
199205 throw SftpError ('Download timed out at offset=$offset ' );
200206 }
201- offset += length;
207+
208+ if (segmentBytes == 0 ) {
209+ throw SftpError (
210+ 'Download returned 0 bytes at offset=$offset ' ,
211+ );
212+ }
213+ offset += segmentBytes;
202214 }
203215
204216 Loggers .app.info (
Original file line number Diff line number Diff line change @@ -567,7 +567,9 @@ class ServerNotifier extends _$ServerNotifier {
567567 bool isWindows = false ,
568568 }) async {
569569 final spi = state.spi;
570- final execResult = await client.run (statusCmd);
570+ final execResult = await client
571+ .run (statusCmd)
572+ .timeout (const Duration (seconds: 30 ));
571573 return SSHDecoder .decode (
572574 execResult,
573575 isWindows: isWindows,
You can’t perform that action at this time.
0 commit comments