Sample code for 30+ languages & platforms
Dart

SFTP SymLink - Create Symbolic Link on Server

See more SFTP Examples

Demonstrates how to create a symbolic link on the SFTP server.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  var success = false;

  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  final sftp = CkSFtp();

  // Pass a domain or IP address..
  success = true;
  try {
    sftp.connect('my-sftp-server.com', 22);
  } on ChilkatException {
    success = false;
  }
  if (success) {
    success = true;
    try {
      sftp.authenticatePw('mySFtpLogin', 'mySFtpPassword');
    } on ChilkatException {
      success = false;
    }
  }

  if (success) {
    success = true;
    try {
      sftp.initializeSftp();
    } on ChilkatException {
      success = false;
    }
  }

  if (!success) {
    print(sftp.lastErrorText);
    return;
  }

  // Create a symbolic link on the server.
  // We'll create a link in our HOME directory named "sshd_config"
  // which points to the file /etc/ssh/sshd_config.
  success = true;
  try {
    sftp.symLink('/etc/ssh/sshd_config', 'sshd_config');
  } on ChilkatException {
    success = false;
  }
  if (!success) {
    print(sftp.lastErrorText);
    return;
  }

  print('Successfully created symbolic link.');
}