ftpconnect 3.0.0 copy "ftpconnect: ^3.0.0" to clipboard
ftpconnect: ^3.0.0 copied to clipboard

Simple and robust dart FTP Connect Library to interact with FTP Servers.

example/main.dart

import 'dart:io';

import 'package:ftpconnect/ftpconnect.dart';

void main() async {
  final FTPConnect ftpConnect = FTPConnect(
    "users.on.net",
    user: "pvpt",
    pass: "Lachdhaf",
    showLog: true,
  );

  ///an auxiliary function that manage showed log to UI
  Future<void> log(String log) async {
    print(log);
    await Future.delayed(Duration(seconds: 1));
  }

  ///mock a file for the demonstration example
  Future<File> fileMock({fileName = 'FlutterTest.txt', content = ''}) async {
    final Directory directory = Directory('/test')..createSync(recursive: true);
    final File file = File('${directory.path}/$fileName');
    await file.writeAsString(content);
    return file;
  }

  Future<void> uploadStepByStep() async {
    try {
      await log('Connecting to FTP ...');
      await ftpConnect.connect();
      await ftpConnect.changeDirectory('upload');
      File fileToUpload = await fileMock(
          fileName: 'uploadStepByStep.txt', content: 'uploaded Step By Step');
      await log('Uploading ...');
      await ftpConnect.uploadFile(fileToUpload);
      await log('file uploaded sucessfully');
      await ftpConnect.disconnect();
    } catch (e) {
      await log('Error: ${e.toString()}');
    }
  }

  Future<void> downloadStepByStep() async {
    try {
      await log('Connecting to FTP ...');

      await ftpConnect.connect();

      await log('Downloading ...');
      String fileName = '../512KB.zip';

      //here we just prepare a file as a path for the downloaded file
      File downloadedFile = await fileMock(fileName: 'downloadStepByStep.txt');
      await ftpConnect.downloadFile(fileName, downloadedFile);
      await log('file downloaded path: ${downloadedFile.path}');
      await ftpConnect.disconnect();
    } catch (e) {
      await log('Downloading FAILED: ${e.toString()}');
    }
  }

  await uploadStepByStep();
  await downloadStepByStep();
}
141
likes
160
points
5.41k
downloads

Documentation

API reference

Publisher

verified publishersalimdev.ovh

Weekly Downloads

Simple and robust dart FTP Connect Library to interact with FTP Servers.

Homepage
Repository (GitHub)
View/report issues

Topics

#sftp #ftp #ftpes #ftps #ftp-client

License

MIT (license)

Dependencies

dartssh2, intl, path

More

Packages that depend on ftpconnect