Dart
Dart
Append to Existing File on FTP Server
See more FTP Examples
Uploads a file to the FTP server. If the remote file (on the FTP server) does not already exist, it is created. Otherwise the uploaded file is appended to the remote file.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.myftpserver.com';
ftp.username = 'myUsername';
ftp.password = 'myPassword';
// 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 localFilePath = '/someDirectory/hamlet.xml';
final remoteFilename = 'hamlet.xml';
// Upload to the FTP server, creating the file if it does not yet exist
// on the FTP server, or appending to the remote file if it already exists.
try {
ftp.appendFile(localFilePath, remoteFilename);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
ftp.disconnect();
print('Success.');
}