ftpconnect
Simple and robust dart FTP Connect Library to interact with FTP Servers.
dartFTP
English project snapshot. Visit GitHub for the latest content.
Key Features • Examples • Parameters • SFTP Support • License
This library is originally based on dart_ftpclient, which has not been updated in years.
import 'dart:io';
import 'package:ftpconnect/ftpconnect.dart';
main() async{
FTPConnect ftpConnect = FTPConnect('example.com',user:'user', pass:'pass');
File fileToUpload = File('fileToUpload.txt');
await ftpConnect.connect();
bool res = await ftpConnect.uploadFile(fileToUpload);
await ftpConnect.disconnect();
print(res);
}
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
}
}
import 'dart:io';
import 'package:ftpconnect/ftpconnect.dart';
main() async{
FTPConnect ftpConnect = FTPConnect('example.com',user:'user', pass:'pass');
String fileName = 'toDownload.txt';
await ftpConnect.connect();
bool res = await ftpConnect.downloadFile(fileName, File('myFileFromFTP.txt'));
await ftpConnect.disconnect();
print(res);
}
import 'dart:io';
import 'package:ftpconnect/ftpconnect.dart';
main() async {
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
}
}
//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');
//Delete a non-empty directory (recursively)
ftpConnect.deleteNonEmptyDirectory('dirToDelete');
//check for directory existance
ftpConnect.checkFolderExistence('dirToCheck');
//create a directory if it does not exist
ftpConnect.createFolderIfNotExist('dirToCreate');
//Upload a local directory recursively to the server
ftpConnect.uploadDirectory(Directory('localDir'), 'remoteDir');
//Download a remote directory recursively
ftpConnect.downloadDirectory('remoteDir', Directory('localDir'));
//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');
//upload in-memory bytes (no local file needed)
ftpConnect.uploadData(Uint8List.fromList([1, 2, 3]), 'remote.bin');
//download a remote file into memory as bytes
final Uint8List bytes = await ftpConnect.downloadToBytes('remote.bin');
FTPConnect and SFTPConnect)| Property | Description |
|---|---|
host |
Hostname or IP Address |
port |
Port number (FTP defaults to 21, FTPS to 990, SFTP to 22) |
user |
Username (Defaults to anonymous) |
pass |
Password if not anonymous login |
showLog |
Enable Debug Logging (Defaults to false) |
logger |
Custom logger |
timeout |
Timeout in seconds to wait for responses (Defaults to 30) |
FTPConnect)| Property | Description |
|---|---|
securityType |
SecurityType.ftp / ftpes / ftps (Defaults to ftp) |
SFTPConnect)| Property | Description |
|---|---|
privateKey |
PEM/OpenSSH private key content, used instead of pass |
passphrase |
Passphrase protecting privateKey (if any) |
onVerifyHostKey |
Optional host key verification handler |
More details here.
SFTP is provided by the SFTPConnect class, powered by the pure-Dart
dartssh2 package. Both FTPConnect and
SFTPConnect implement the same FileTransferClient interface, so they share
identical method names/signatures and you can swap one for the other by changing
only the instantiated class.
ℹ️
dartssh2is written in pure Dart, soSFTPConnectworks on every platform supported by Dart/Flutter (except web, which has no raw TCP sockets).
import 'dart:io';
import 'package:ftpconnect/ftpconnect.dart';
main() async {
SFTPConnect sftpConnect = SFTPConnect(
'example.com',
port: 22,
user: 'user',
pass: 'pass',
showLog: true,
);
try {
await sftpConnect.connect();
// Upload a file
File fileToUpload = File('fileToUpload.txt');
await sftpConnect.uploadFile(fileToUpload);
// List directory content
List<FTPEntry> content = await sftpConnect.listDirectoryContent('.');
print(content);
// Download a file
await sftpConnect.downloadFile('toDownload.txt', File('myFile.txt'));
// Manage files/directories
await sftpConnect.makeDirectory('newDir');
await sftpConnect.rename('test1.txt', 'test2.txt');
await sftpConnect.deleteFile('test2.txt');
await sftpConnect.disconnect();
} catch (e) {
// error
}
}
Authenticating with a private key instead of a password:
SFTPConnect sftpConnect = SFTPConnect(
'example.com',
user: 'user',
privateKey: '''-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----''',
passphrase: 'passphrase-for-key',
);
If this plugin was useful to you, helped you to deliver your app, saved you a lot of time, or you just want to support the project, I would be very grateful if you buy me a cup of coffee.
MIT
Start with your use case, compare repository activity, and check the original project before adopting it.
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗