Site icon Flutter Packages | Pub dev Packages – Flutter Mobile App World

A simple and robust dart FTP Client Library

Flutter FTP Connect

Flutter simple and robust dart FTP Connect Library to interact with FTP Servers with possibility of zip and unzip files.

Key Features • Examples • License

Key Features

Example upload file

###example 1:

import 'dart:io';
import 'package:ftpconnect/ftpConnect.dart';

main() async{
    FTPConnect ftpConnect = FTPConnect('example.com',user:'user', pass:'pass');
    File fileToUpload = File('fileToUpload.txt');
    bool res = await ftpConnect.uploadFileWithRetry(fileToUpload, pRetryCount: 2);
    print(res);
}

###example 2: step by step

import 'dart:io';
import 'package:ftpconnect/ftpConnect.dart';

main() async{
  FTPConnect ftpConnect = FTPConnect('example.com',user:'user', pass:'pass');
 try {
      File fileToUpload = File('fileToUpload.txt');
      await ftpConnect.connect();
      await ftpConnect.uploadFile(fileToUpload);
      await ftpConnect.disconnect();
    } catch (e) {
      //error
    }
}

Download file

###example 1:

import 'dart:io';
import 'package:ftpconnect/ftpConnect.dart';

main() async{
    FTPConnect ftpConnect = FTPConnect('example.com',user:'user', pass:'pass');
    String fileName = 'toDownload.txt';
    bool res = await ftpConnect.downloadFileWithRetry(fileName, File('myFileFromFTP.txt'));
    print(res)
}

###example 2: step by step

import 'dart:io';
import 'package:ftpconnect/ftpConnect.dart';

main() {
  FTPConnect ftpConnect = FTPConnect('example.com',user:'user', pass:'pass');
 try {
      String fileName = 'toDownload.txt';
      await ftpConnect.connect();
      await ftpConnect.downloadFile(fileName, File('myFileFromFTP.txt'));
      await ftpConnect.disconnect();
    } catch (e) {
      //error
    }
}

Other Features

###Directory functions:

//Get directory content
ftpConnect.listDirectoryContent();

//Create directory
ftpConnect.makeDirectory('newDir');

//Change directory
ftpConnect.changeDirectory('moveHereDir');

//get current directory
ftpConnect.currentDirectory();

//Delete directory
ftpConnect.deleteDirectory('dirToDelete');

//check for directory existance
ftpConnect.checkFolderExistence('dirToCheck');

//create a directory if it does not exist
ftpConnect.createFolderIfNotExist('dirToCreate');

###File functions:

//rename file
ftpConnect.rename('test1.txt', 'test2.txt');

//file size
ftpConnect.sizeFile('test1.txt');

//file existence
ftpConnect.existFile('test1.txt');

//delete file
ftpConnect.deleteFile('test2.zip');

###Zip functions:

//compress a list of files/directories into Zip file
FTPConnect.zipFiles(List<String> paths, String destinationZipFile);

//unzip a zip file
FTPConnect.unZipFile(File zipFile, String destinationPath, {password});

Paramaters

PropertiesDescription
hostHostname or IP Address
portPort number (Defaults to 21)
userUsername (Defaults to anonymous)
passPassword if not anonymous login
debugEnable Debug Logging
timeoutTimeout in seconds to wait for responses (Defaults to 30)

Download Flutter FTP Connect plugin source code on GitHub

https://github.com/salim-lachdhaf/ftpConnect
Exit mobile version