Dart
Dart
FTP Upload / Download to StringBuilder
Demonstrate how to upload from a Chilkat StringBuilder object, and download into a StringBuilder 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 sbA = CkStringBuilder();
sbA.loadFile('qa_data/hamlet.xml', 'utf-8');
// Upload the contents of sbA to the FTP server.
final bIncludeBOM = false;
final remoteFilename = 'hamletFromSb.xml';
try {
ftp.putFileSb(sbA, 'utf-8', bIncludeBOM, remoteFilename);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Download...
final sbB = CkStringBuilder();
try {
ftp.getFileSb(remoteFilename, 'utf-8', sbB);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Verify that sbA and sbB have the exact same contents.
print('size of sbA: ${sbA.length}');
final bCaseSensitive = true;
if (sbA.contentsEqualSb(sbB, bCaseSensitive)) {
print('Contents are equal. Success.');
} else {
print('Contents are NOT equal. Failed.');
}
ftp.disconnect();
}