Dart
Dart
Save String Variable to File on FTP Server
See more FTP Examples
Save the contents of a string variable to a file on an FTP server.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final ftp = CkFtp2();
ftp.hostname = 'ftp.example.com';
ftp.username = 'login';
ftp.password = 'password';
// Connect and login to the FTP server.
try {
ftp.connect();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Change to the remote directory where the existing file is located.
try {
ftp.changeRemoteDir('junk');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Upload the contents of a string to a remote file.
final fileContents = 'To be, or not to be: that is the question.';
final remoteFilename = 'hamletQuote.txt';
try {
ftp.putFileFromTextData(remoteFilename, fileContents, 'utf-8');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
ftp.disconnect();
print('String Uploaded!');
}