You are here

function drupal_ftp_connect in Backup and Migrate 6.2

Same name and namespace in other branches
  1. 8.2 includes/destinations.ftp.inc \drupal_ftp_connect()
  2. 8.3 includes/destinations.ftp.inc \drupal_ftp_connect()
  3. 6.3 includes/destinations.ftp.inc \drupal_ftp_connect()
  4. 7.3 includes/destinations.ftp.inc \drupal_ftp_connect()
  5. 7.2 includes/destinations.ftp.inc \drupal_ftp_connect()

The drupal_ftp_connect function This function connects to an FTP server and attempts to change into the directory specified by the fourth parameter, $directory.

6 calls to drupal_ftp_connect()
drupal_ftp_change_directory in includes/destinations.ftp.inc
The drupal_ftp_change_directory Function This function simply changes into the $directory folder on the FTP server. If a connection or permission error occurs then _backup_migrate_message() will contain the error message.
drupal_ftp_create_directory in includes/destinations.ftp.inc
The drupal_ftp_create_directory Function This function tries to make a new directory called $folder_name on the FTP server. If it can create the folder, then the folder is given appropriate rights with the CHMOD command.
drupal_ftp_delete_file in includes/destinations.ftp.inc
The drupal_ftp_delete_file Function This function attempts to delete a file called $filename from the FTP server.
drupal_ftp_delete_folder in includes/destinations.ftp.inc
The drupal_ftp_delete_folder Function This function was one of the hardest to write. It recursively deletes all files and folders from a directory called $folder_name.
drupal_ftp_file_to_ftp in includes/destinations.ftp.inc
Send a file to an FTP server.

... See full list

File

includes/destinations.ftp.inc, line 131
Functions to handle the FTP backup destination.

Code

function drupal_ftp_connect(&$ftp) {
  if (is_NULL($ftp)) {
    $ftp = drupal_ftp_ftp_object();
  }
  if (empty($ftp->__conn) && !drupal_ftp_connected($ftp)) {

    // Attempt to connect to the remote server
    $ftp->__conn = @ftp_connect($ftp->__server, $ftp->__port);
    if (!$ftp->__conn) {
      _backup_migrate_message('FTP Error: Couldn\'t connect to server @server', array(
        '@server' => $ftp->__server,
      ), 'error');
      return FALSE;
    }

    // Attempt to login to the remote server
    $ftp->__login = @ftp_login($ftp->__conn, $ftp->__user, $ftp->__password);
    if (!$ftp->__login) {
      _backup_migrate_message('FTP Error: Couldn\'t login as user @ftp_user to @server', array(
        '@ftp_user' => $ftp->__user,
        '@server' => $ftp->__server,
      ), 'error');
      return FALSE;
    }

    // Attempt to change into the working directory
    $chdir = @ftp_chdir($ftp->__conn, $ftp->__directory);
    if (!$chdir) {
      _backup_migrate_message('FTP Error: Couldn\'t change into the @directory directory', array(
        '@directory' => $ftp->__directory,
      ), 'error');
      return FALSE;
    }

    // Set PASV - if needed
    if ($ftp->__pasv) {
      $pasv = @ftp_pasv($ftp->__conn, TRUE);
      if (!$pasv) {
        _backup_migrate_message('FTP Error: Couldn\'t set PASV mode', array(), 'error');
        return FALSE;
      }
    }
  }

  // Everything worked OK, return TRUE
  return TRUE;
}