From 97c80d29a936618e4bd06a0de6c7e019990a2b3f Mon Sep 17 00:00:00 2001 From: artem Date: Sat, 18 May 2024 01:47:54 +0300 Subject: [PATCH 1/7] potentially fix https://github.com/crifurch/pure_ftp/issues/24 --- example/pure_ftp_example.dart | 5 ++++- lib/src/file_system/ftp_transfer.dart | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/example/pure_ftp_example.dart b/example/pure_ftp_example.dart index 89b257f..30670cc 100644 --- a/example/pure_ftp_example.dart +++ b/example/pure_ftp_example.dart @@ -4,7 +4,7 @@ import 'package:pure_ftp/pure_ftp.dart'; import 'package:yaml/yaml.dart'; void main() async { - final configFile = File('default_connection.yml'); + final configFile = File('test_connection2.yml'); final config = loadYaml(await configFile.readAsString()); final client = FtpClient( @@ -31,6 +31,9 @@ void main() async { // maybe server doesn't support MLSD print(e); } + final childFile = + client.currentDirectory.getChildFile('capscraft.com/api/backend_'); + await client.fs.downloadFile(childFile); await client.disconnect(); } diff --git a/lib/src/file_system/ftp_transfer.dart b/lib/src/file_system/ftp_transfer.dart index b471e27..2be1aea 100644 --- a/lib/src/file_system/ftp_transfer.dart +++ b/lib/src/file_system/ftp_transfer.dart @@ -68,7 +68,6 @@ class FtpTransfer { log?.call('Downloaded ${downloaded} of ${total} bytes'); }, ).asFuture(); - await _socket.read(); await stream.close(); }, (error, stackTrace) { @@ -110,7 +109,7 @@ class FtpTransfer { uploaded += event.length; final total = max(fileSize, uploaded); onUploadProgress?.call(uploaded, total, uploaded / total * 100); - log?.call('Downloaded ${uploaded} of ${total} bytes'); + log?.call('Uploaded ${uploaded} of ${total} bytes'); }, ), ); From 66afbd0c8f689f2c8a67633dc524c3535eff16fd Mon Sep 17 00:00:00 2001 From: artem Date: Sat, 18 May 2024 01:52:36 +0300 Subject: [PATCH 2/7] revert some changes --- example/pure_ftp_example.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/example/pure_ftp_example.dart b/example/pure_ftp_example.dart index 30670cc..89b257f 100644 --- a/example/pure_ftp_example.dart +++ b/example/pure_ftp_example.dart @@ -4,7 +4,7 @@ import 'package:pure_ftp/pure_ftp.dart'; import 'package:yaml/yaml.dart'; void main() async { - final configFile = File('test_connection2.yml'); + final configFile = File('default_connection.yml'); final config = loadYaml(await configFile.readAsString()); final client = FtpClient( @@ -31,9 +31,6 @@ void main() async { // maybe server doesn't support MLSD print(e); } - final childFile = - client.currentDirectory.getChildFile('capscraft.com/api/backend_'); - await client.fs.downloadFile(childFile); await client.disconnect(); } From bb1acab68742e64663dd01b84ecde4cecea8f85a Mon Sep 17 00:00:00 2001 From: artem Date: Sat, 18 May 2024 02:00:39 +0300 Subject: [PATCH 3/7] add flush method to ftp_socket.dart --- lib/src/file_system/ftp_transfer.dart | 1 + lib/src/ftp/ftp_socket.dart | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/src/file_system/ftp_transfer.dart b/lib/src/file_system/ftp_transfer.dart index 2be1aea..7945280 100644 --- a/lib/src/file_system/ftp_transfer.dart +++ b/lib/src/file_system/ftp_transfer.dart @@ -68,6 +68,7 @@ class FtpTransfer { log?.call('Downloaded ${downloaded} of ${total} bytes'); }, ).asFuture(); + await _socket.flush(); await stream.close(); }, (error, stackTrace) { diff --git a/lib/src/ftp/ftp_socket.dart b/lib/src/ftp/ftp_socket.dart index 723ef14..efe272b 100644 --- a/lib/src/ftp/ftp_socket.dart +++ b/lib/src/ftp/ftp_socket.dart @@ -190,6 +190,21 @@ class FtpSocket { return FtpResponse(code: code, message: result); } + /// Flush the response from the server + Future flush() async { + await Future.doWhile(() async { + if (_socket.available() > 0) { + _socket.readMessage(); + return false; + } + await Future.delayed(const Duration(milliseconds: 300)); + return true; + }); + if (_socket.available() > 0) { + await flush(); + } + } + /// Send message to the server /// /// if [command] is true then the message will be sent as a command From 64b98a545409c9b8a64d5dcfa70bac70675d2cbb Mon Sep 17 00:00:00 2001 From: artem Date: Sat, 18 May 2024 02:03:15 +0300 Subject: [PATCH 4/7] small fix flush method in ftp_socket.dart --- lib/src/ftp/ftp_socket.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/ftp/ftp_socket.dart b/lib/src/ftp/ftp_socket.dart index efe272b..6baf544 100644 --- a/lib/src/ftp/ftp_socket.dart +++ b/lib/src/ftp/ftp_socket.dart @@ -198,7 +198,7 @@ class FtpSocket { return false; } await Future.delayed(const Duration(milliseconds: 300)); - return true; + return false; }); if (_socket.available() > 0) { await flush(); From 526a6842d339dd5b815dc6ec05d59c3399c5a28f Mon Sep 17 00:00:00 2001 From: artem Date: Sat, 18 May 2024 02:05:16 +0300 Subject: [PATCH 5/7] small fix flush method in ftp_socket.dart --- example/pure_ftp_example.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/example/pure_ftp_example.dart b/example/pure_ftp_example.dart index 89b257f..57c2659 100644 --- a/example/pure_ftp_example.dart +++ b/example/pure_ftp_example.dart @@ -4,7 +4,7 @@ import 'package:pure_ftp/pure_ftp.dart'; import 'package:yaml/yaml.dart'; void main() async { - final configFile = File('default_connection.yml'); + final configFile = File('test_connection2.yml'); final config = loadYaml(await configFile.readAsString()); final client = FtpClient( @@ -31,6 +31,8 @@ void main() async { // maybe server doesn't support MLSD print(e); } + final childFile = client.currentDirectory.getChildFile('test1'); + await client.fs.downloadFile(childFile); await client.disconnect(); } From b5acc8c9938d48e63e2b3228372aca1052e8b0a9 Mon Sep 17 00:00:00 2001 From: artem Date: Sat, 18 May 2024 02:15:54 +0300 Subject: [PATCH 6/7] small fix flush method in ftp_socket.dart --- lib/src/ftp/ftp_socket.dart | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/src/ftp/ftp_socket.dart b/lib/src/ftp/ftp_socket.dart index 6baf544..b120727 100644 --- a/lib/src/ftp/ftp_socket.dart +++ b/lib/src/ftp/ftp_socket.dart @@ -192,14 +192,10 @@ class FtpSocket { /// Flush the response from the server Future flush() async { - await Future.doWhile(() async { - if (_socket.available() > 0) { - _socket.readMessage(); - return false; - } - await Future.delayed(const Duration(milliseconds: 300)); - return false; - }); + if (_socket.available() > 0) { + _socket.readMessage(); + } + await Future.delayed(const Duration(milliseconds: 300)); if (_socket.available() > 0) { await flush(); } From a2b5c5cd85c91720ace4eb79de7d73a1bc1bdbfa Mon Sep 17 00:00:00 2001 From: artem Date: Sat, 18 May 2024 02:16:32 +0300 Subject: [PATCH 7/7] Revert "small fix flush method in ftp_socket.dart" This reverts commit 526a6842d339dd5b815dc6ec05d59c3399c5a28f. --- example/pure_ftp_example.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/example/pure_ftp_example.dart b/example/pure_ftp_example.dart index 57c2659..89b257f 100644 --- a/example/pure_ftp_example.dart +++ b/example/pure_ftp_example.dart @@ -4,7 +4,7 @@ import 'package:pure_ftp/pure_ftp.dart'; import 'package:yaml/yaml.dart'; void main() async { - final configFile = File('test_connection2.yml'); + final configFile = File('default_connection.yml'); final config = loadYaml(await configFile.readAsString()); final client = FtpClient( @@ -31,8 +31,6 @@ void main() async { // maybe server doesn't support MLSD print(e); } - final childFile = client.currentDirectory.getChildFile('test1'); - await client.fs.downloadFile(childFile); await client.disconnect(); }