Dart
Dart
FTP Upload / Download to a BinData Object
Demonstrates how to FTP upload the contents of a BinData object, and FTP downloads to the a BinData object.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example assumes Chilkat Ftp2 to have been previously unlocked.
// See Unlock Ftp2 for sample code.
final ftp = CkFtp2();
ftp.hostname = 'www.my-ftp-server.com';
ftp.username = 'mFtpLogin';
ftp.password = 'myFtpPassword';
// Connect to the FTP server.
try {
ftp.connectOnly();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Authenticate with the FTP server.
try {
ftp.loginAfterConnectOnly();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final bdA = CkBinData();
bdA.loadFile('qa_data/jpg/penguins.jpg');
// Upload the contents of bdA to the FTP server.
final remoteFilename = 'penguins.jpg';
try {
ftp.putFileBd(bdA, remoteFilename);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Download...
final bdB = CkBinData();
try {
ftp.getFileBd(remoteFilename, bdB);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Verify that bdA and bdB have the exact same contents.
print('size of bdA: ${bdA.numBytes}');
if (bdA.contentsEqual(bdB)) {
print('Contents are equal. Success.');
} else {
print('Contents are NOT equal. Failed.');
}
ftp.disconnect();
}