Giter VIP home page Giter VIP logo

dart_ftpclient's Introduction

A small and simple FTP Client library for Dart Native.

Pub Version GitHub license Build Status GitHub issues

⚠️ This lib is currently under development, the API might change until the first Major release!

Usage

Add the following dependency to the pubspec.yaml

Stable

dependencies:
  ftpclient: ^0.8.0

Development

dependencies:
  ftpclient: ^0.9.0

NOTE: This version is not yet available on pub.dev

How to use the FTP Client:

import 'dart:io';
import 'package:ftpclient/ftpclient.dart';

main() {
  FTPClient ftpClient = FTPClient('example.com', user: 'myname', pass: 'mypass');
  ftpClient.connect();
  ftpClient.uploadFile(File('test.zip'));
  ftpClient.disconnect();
}

For a complete example, see the examples in the example folder!

Tested FTP Servers

We have tested the lib with the following FTP Servers:

  • ProFTPd

dart_ftpclient's People

Contributors

midna92 avatar virtualmarc avatar wwwdata avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dart_ftpclient's Issues

listDirectoryContent() gets stuck with message "about to open data connection"

Describe the bug
The listDirectoryContent() method gets stuck indefinitely. If the debug is set to true, we can see this log:

I/flutter ( 4570): [17.01.2021 15:14:43.636] Connecting...
I/flutter ( 4570): [17.01.2021 15:14:43.840] < 220 Service ready for new user.
I/flutter ( 4570): [17.01.2021 15:14:43.841] > USER anonymous
I/flutter ( 4570): [17.01.2021 15:14:44.144] < 331 Guest login okay, send your complete e-mail address as password.
I/flutter ( 4570): [17.01.2021 15:14:44.144] > PASS
I/flutter ( 4570): [17.01.2021 15:14:44.246] < 230 User logged in, proceed.
I/flutter ( 4570): [17.01.2021 15:14:44.246] Connected!
I/flutter ( 4570): Connected successfully
I/flutter ( 4570): [17.01.2021 15:14:44.250] > PWD
I/flutter ( 4570): [17.01.2021 15:14:44.351] < 257 "/" is current directory.
I/flutter ( 4570): /
I/flutter ( 4570): [17.01.2021 15:14:44.354] > TYPE A
I/flutter ( 4570): [17.01.2021 15:14:44.455] < 200 Command TYPE okay.
I/flutter ( 4570): [17.01.2021 15:14:44.455] > PASV
I/flutter ( 4570): [17.01.2021 15:14:44.556] < 227 Entering Passive Mode (192,168,1,8,167,251)
I/flutter ( 4570): [17.01.2021 15:14:44.558] > MLSD
I/flutter ( 4570): [17.01.2021 15:14:44.569] < 150 File status okay; about to open data connection.

And it gets stuck at this point. The listDirectoryContent() method never returns.

Code Snippet:

FTPClient ftpClient = FTPClient(host.text,
            port: int.parse(port.text),
            user: username.text.isEmpty ? "anonymous" : username.text,
            pass: password.text,
            debug: true);
ftpClient.connect();     

debugPrint("Connected successfully");
debugPrint(ftpClient.currentDirectory());

var dirs = ftpClient.listDirectoryContent();         // <-- It gets stuck here
ftpClient.disconnect();

for (var dir in dirs) {
  debugPrint(dir.name);
}

Expected behavior
listDirectoryContent() returns the directory content, or throws a proper error.

Platform:

  • Flutter

Smartphone (when using Flutter):

  • Device: OnePlus 8 Pro
  • OS: Oxygen OS 11.0.2.2 [Android Version 11]

FTP Server Software

  • Dragon Touch Picture Frame FTP

Can't run upload example

Describe the bug
When running the upload example I get an exception type 'OSError' is not a subtype of type 'int' and the file received on the server is 0 byte long.

Expected behavior
A successful upload of the choosen file.

Platform:
Dart Native

FTP Server Software

  • ProFTPd
  • vsftpd

Log
Enable the debug Flag in the Constructor and paste the Log. Remember to remove sensitive information!

[14.03.2021 23:34:09.719] Connecting...
[14.03.2021 23:34:09.732] < 220 ProFTPD Server (ProFTPD Default Installation) [127.0.0.1]
[14.03.2021 23:34:09.732] > USER luke
[14.03.2021 23:34:09.838] < 331 Password required for luke
[14.03.2021 23:34:09.838] > PASS *************
[14.03.2021 23:34:09.939] < 230 User luke connected
[14.03.2021 23:34:09.939] Connected!
[14.03.2021 23:34:09.949] Upload File: test.zip
[14.03.2021 23:34:09.950] > TYPE I
[14.03.2021 23:34:10.051] < 200 Type set to I
[14.03.2021 23:34:10.051] > PASV
[14.03.2021 23:34:10.151] < 227 Entering Passive Mode (127,0,0,1,138,203).
[14.03.2021 23:34:10.173] > STOR test.zip
[14.03.2021 23:34:10.176] Opening DataSocket to Port 35531
[14.03.2021 23:34:10.182] Disconnecting...
[14.03.2021 23:34:10.182] > QUIT

Async operations

Thank you for this nice library.

I see that all your functions are sync. Is there any plan to provide async commands ?

File sent to server is empty

When trying to send a file to an FTP server, the received file is 0 bytes, also when sending files to the company server filenames get jumbled except for the first charchter.

To Reproduce
I tested this on a public FTP server (https://dlptest.com/ftp-test/) as well as my company's server, both in ascii and binary mode, with the following code:

 Future<String> sendFileTest(File file) async {
    //TODO:remove this method
    String status = "failure";
    final FTPClient ftp =
        FTPClient("ftp.dlptest.com",
            user: "[email protected]",
            pass: "SzMf7rTE4pCrf9dV286GuNe4N",
            debug: true,
            timeout: 10);
    try {
      ftp.connect();
    } catch (e) {
      print(e);
      return status;
    }
    try {
      ftp.uploadFile(file, mode: TransferMode.binary);
      status = "success";
    } catch (e) {
      print(e);
      return status;
    } finally {
      ftp.disconnect();
    }
    return status;
  }

Screenshots
files when sent to the public server, notice they are 0 bytes
sent-to-public-server

files when sent to the company server, filename is wrong except for the first letter
sent-to-company-server

Platform:

  • Flutter

Smartphone (when using Flutter):

  • Devices: Huawei p20 pro CLT L29[Android 9],
    Android Emulator[Android 6]

Log

I/flutter ( 3692): [29.04.2020 14:55:54.548] Connecting...
I/flutter ( 3692): [29.04.2020 14:55:54.753] < 220 (vsFTPd 2.0.5)
I/flutter ( 3692): [29.04.2020 14:55:54.754] > USER usr_ftp
I/flutter ( 3692): [29.04.2020 14:55:54.857] < 331 Please specify the password.
I/flutter ( 3692): [29.04.2020 14:55:54.857] > PASS ftp_usr
I/flutter ( 3692): [29.04.2020 14:55:54.960] < 230 Login successful.
I/flutter ( 3692): [29.04.2020 14:55:54.960] Connected!
I/flutter ( 3692): [29.04.2020 14:55:54.960] > CWD /colombus/timeless/exprecup/inventar
I/flutter ( 3692): [29.04.2020 14:55:55.063] < 250 Directory successfully changed.
I/flutter ( 3692): [29.04.2020 14:55:55.064] Upload File: /data/user/0/com.frista.inventoryscanner/app_flutter/awaitingFolder/8J88_29-04-2020_14:51:43.PAQ
I/flutter ( 3692): [29.04.2020 14:55:55.065] > TYPE I
I/flutter ( 3692): [29.04.2020 14:55:55.169] < 200 Switching to Binary mode.
I/flutter ( 3692): [29.04.2020 14:55:55.169] > PASV
I/flutter ( 3692): [29.04.2020 14:55:55.272] < 227 Entering Passive Mode (10,101,0,1,227,240)
I/flutter ( 3692): [29.04.2020 14:55:55.272] > STOR 8J88_29-04-2020_14:51:43.PAQ
I/flutter ( 3692): [29.04.2020 14:55:55.273] Opening DataSocket to Port 58352
I/flutter ( 3692): [29.04.2020 14:55:55.273] Disconnecting...
I/flutter ( 3692): [29.04.2020 14:55:55.273] > QUIT
I/flutter ( 3692): [29.04.2020 14:55:55.274] Disconnected!
E/flutter ( 3692): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type 'OSError' is not a subtype of type 'int'
E/flutter ( 3692): #0      _NativeSynchronousSocket.available (dart:io-patch/sync_socket_patch.dart:122:24)
E/flutter ( 3692): #1      _RawSynchronousSocket.available (dart:io-patch/sync_socket_patch.dart:33:30)
E/flutter ( 3692): #2      FTPSocket.readResponse (package:ftpclient/src/ftpsocket.dart:33:25)
E/flutter ( 3692): #3      FileUpload.uploadFile (package:ftpclient/src/commands/fileupload.dart:48:36)
E/flutter ( 3692): <asynchronous suspension>
E/flutter ( 3692): #4      FTPClient.uploadFile (package:ftpclient/src/ftpclient_base.dart:58:43)
E/flutter ( 3692): #5      FTPManager.sendFileTest (package:inventoryscanner/Logic/FTPManager.dart:31:11)
E/flutter ( 3692): #6      _FileCardState.build.<anonymous closure> (package:inventoryscanner/Elements/FileCard.dart:88:24)
E/flutter ( 3692): <asynchronous suspension>
E/flutter ( 3692): #7      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14)
E/flutter ( 3692): #8      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789:36)
E/flutter ( 3692): #9      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 3692): #10     TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
E/flutter ( 3692): #11     BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
E/flutter ( 3692): #12     BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:236:7)
E/flutter ( 3692): #13     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter ( 3692): #14     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20)
E/flutter ( 3692): #15     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter ( 3692): #16     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 3692): #17     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 3692): #18     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 3692): #19     _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter ( 3692): #20     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter ( 3692): #21     _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter ( 3692): #22     _invoke1 (dart:ui/hooks.dart:273:10)
E/flutter ( 3692): #23     _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
E/flutter ( 3692): 

Connection to server doesn't time out according to timeout parameter

When attempting to connect to a server, if the server is unavailable, the connection times out after over two minutes, instead of the timeout value previously set.

Smartphone:

  • Device: Huawei p20 pro CLT-L29
  • OS: Android 9

Log
...
I/flutter ( 8045): [25.04.2020 18:02:29.330] Connecting...
I/flutter ( 8045): SocketException: Connection failed (OS Error: Connection timed out, errno = 110), address = 10.101.0.1, port = 21


The timeout happened after 2 minutes and 15 seconds, while the timeout value was set to 10 seconds in the FTPClient constructor

FtpUpload Buffer Size

Hi,
I am using ftpclient to upload files from my devices to my FTP site.
Everything works fine, but when the transferred file is small (minus 1 Mb), I found a damaged partial file on my FTP site.
Below my code:
bool uploadFile(String PathFileName) {
FTPClient ftpClient = new FTPClient(Host, user: Username, pass: Password);
try {
ftpClient.connect();
ftpClient.uploadFile(new File(PathFileName));
sleep(Duration(seconds: 5));
ftpClient.disconnect();
return true;
} catch (ex) {
debugPrint(ex.toString());
return false;
}
}

To workaround I insert a sleep before Disconnect method.
The right solution is to change the Buffer Size in the class FileUpload {
static const int _BUFFER_SIZE = 1024 * 1024;
I tried to set the _BUFFER_SIZE = 1024; and in this way I don't need to use the sleep.
Seems that the function uploadFile in your class FileUpload exit before transfer is complete. So when my program call disconnect method because it think the transfer is complete, it drops the transfer. I hope the description of my issue is clear.
I'am using android 8, ftpclient: ^0.5.0

Directory List

Hello,
I tried to get the list of files in my FTP directory using the listDirectoryContent () function without success.
Debugging the code, I saw that in the directory.dart file at line 99
sResponse = _socket.readResponse (); goes in times out. Then I added a print of sResponse to the previous line and I get this:
I/flutter (17207): 150 Accepted data connection
I/flutter (17207): 226-Options: -a -l
I/flutter (17207): 226 4 matches total

So the server has already responded with 226.
I commented the line 99 and I changed line 100 on if (! SResponse.contains ('226')) {
just to go on...

After, at line 106 String.fromCharCodes (lstDirectoryListing) .split ('\ n'). ForEach ((line) {
I get others exceptions because the FTPEntry.dart class
does not contain the following properties:
FTPException: Unknown FTPEntry property 'sizd = 4096'
FTPException: Unknown FTPEntry property 'UNIX.uid = 1975'
FTPException: Unknown FTPEntry property 'UNIX.gid = 1974'

I remain available for clarifications or tests.

CHMOD

Add SITE CHMOD command to change file mode

FormatException (FormatException: Missing extension byte (at offset 39))

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Platform:

  • Flutter
  • Dart Native
  • Dart JIT
  • Browser

Smartphone (when using Flutter):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]

FTP Server Software

  • ProFTPd
  • PureFTPd
  • vsftpd
  • etc.

Log
Enable the debug Flag in the Constructor and paste the Log. Remember to remove sensitive information!

Paste Log here

Additional context
Add any other context about the problem here.

can not download an empty file

Describe the bug
if you have an empty file on the FTP the download get freezed

To Reproduce
Steps to reproduce the behavior:

  1. upload or create an empty txt file on the FTP
  2. try with the plugin to download that file
  3. download not working

Platform:

  • Flutter

Smartphone (when using Flutter):

  • Device: Samsung Note

FTP Server Software

  • ProFTPd

List directory not working

I am trying to get the list of directories and files in FTP server and getting below error in flutter
Unhandled Exception: FTPException: Can't get content of directory. (Response: 500 Command not understood.)

socket closing bug

Describe the bug
if we are disconnected (no internet) then the socket is NULL, however, we pass in ftpclient.disconnect() in finally witch call _socket.closeSync(); so the app crashes.

void connect(String user, String pass) {
    _log.log('Connecting...');
    _socket = RawSynchronousSocket.connectSync(host, port);  <- this crashes and the crash maintained by try catch as result we have  _socket =Null
...
}
void disconnect() {
    _log.log('Disconnecting...');

    try {
      sendCommand('QUIT');
    } catch (ignored) {
      // Ignore
    } finally {
      _socket.closeSync();// <- here it crashes
    }

    _log.log('Disconnected!');
  }

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'closeSync' was called on null.

Expected behavior
maybe as solution we have to surrond _socket.closeSync() with try catch or test if _socket !=null

Platform:

  • Flutter

Smartphone (when using Flutter):

  • Device: [Gallaxy Note]

FTP Server Software

  • ProFTPd

FTP Response

Hi
I encountered an problem with ftp response…
my ftp respond in this way:
Unknown response from FTP server (Response: 220-
I have modify your ftpsocket.dart in line 66 if (!sResponse.startsWith('220')) { removing the space.
I removing the space in line 74 and 82 too.
In this way everything goes ok.

FileSystemException during upload file

Hi,

I received an error when I tried to upload a file in my FTP server. Kindly see the details below:

Cannot open file, path = 'upload.txt' (OS Error: No such file or directory, errno = 2)

As i checked, the file was successfully uploaded in the FTP server, but this error is showing in the debug console.

Also my app has a read/write permission in the phone.

Thank you,
Vincent

Update examples

Multiple example files with all use cases should be created.

OT: DWDWarnBot v2.4 by Nexific.com

Hey there,
this issue is completely off-topic but Nexific.com does not load on my end unfortunately.
I assume you are the developers behind the awesome @DWDWarnBot Telegram bot. I am wondering if the source code of the bot is available on GitHub too.

FormatException FormatException: Unexpected extension byte (at offset 38))

Exception : ftpClient.connect(); this line

FTPClient ftpClient = FTPClient('192.168.0.1',
port: 22,
user: 'root',
pass: 'IQANIOT850',
debug: true); // Connect to FTP Server
ftpClient.connect(); //Exception in Connection
debugPrint("Connected successfully");
debugPrint(ftpClient.currentDirectory());
try {
// Upload File
ftpClient.uploadFile(File('assets/situ.txt'));
} finally {
// Disconnect
ftpClient.disconnect();
}

Sqlite db corrupted

When I transfer a backup db file (Sqlite) to ftp. The file is corrupted.
I tested so with a zip file but archive is corrupted too.

My backup or zip file originals are OK and i tested both transfermode (binary and ascii).

I use flutter on tablet Galaxy Tab A.

cordially

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.