Sample code for 30+ languages & platforms
Dart

Quote and SendCommand

See more FTP Examples

Demonstrate the Quote and SendCommand methods.

Chilkat Dart Downloads

Dart
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;
  }

  // Tell the FTP object to keep an in-memory session log
  // so we can see the commands sent to the server,
  // and the responses received back.
  ftp.keepSessionLog = true;

  // Change the current remote directory via the Quote method:
  try {
    ftp.quote('CWD junk');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Move back up 
  // In this case, ChangeRemoteDir sends "CWD .." to the FTP server.
  try {
    ftp.changeRemoteDir('..');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Do the same via the SendCommand method where the
  // raw FTP server response is returned:
  try {
    final serverResponse = ftp.sendCommand('CWD junk');
    print(serverResponse);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
  }

  ftp.disconnect();

  print('Session Log:');
  print(ftp.sessionLog);
}