/**
	 *
	 * @return bool
	 */
	public function connect() {
		if ( ! $this->ftp )
			return false;

		$this->ftp->setTimeout(FS_CONNECT_TIMEOUT);

		if ( ! $this->ftp->SetServer($this->options['hostname'], $this->options['port']) ) {
			$this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
			return false;
		}

		if ( ! $this->ftp->connect() ) {
			$this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
			return false;
		}

		if ( ! $this->ftp->login($this->options['username'], $this->options['password']) ) {
			$this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username']));
			return false;
		}

		$this->ftp->SetType( FTP_BINARY );
		$this->ftp->Passive( true );
		$this->ftp->setTimeout( FS_TIMEOUT );
		return true;
	}
 /**
  * Handles uploading processes of the migration
  *
  * @param array $files Files to upload
  * @param string $ftp_password FTP Password
  * @return bool TRUE on success, FALSE on failure
  */
 function upload_files($files, $ftp_password)
 {
     // Load plugin settings
     $wpmove_options = $this->get_admin_options();
     // Instantiate the FTP class
     $ftp = new ftp();
     // Enter Passive Mode if enabled
     if ($wpmove_options['ftp_passive_mode']) {
         $ftp->Passive(TRUE);
     }
     echo '<span class="code">';
     printf(__('Connecting to %s:%d...', 'WPMove'), $wpmove_options['ftp_hostname'], $wpmove_options['ftp_port']);
     $this->flush_output();
     // Set the hostname and the port
     $ftp->SetServer($wpmove_options['ftp_hostname'], intval($wpmove_options['ftp_port']));
     // Try connecting to the server
     if ($ftp->connect()) {
         echo ' <strong>' . __('Success!', 'WPMove') . '</strong><br>';
         $this->flush_output();
         // Display a different message if no password is given
         if ('' !== $ftp_password) {
             printf(__('Logging in as %s using password...', 'WPMove'), $wpmove_options['ftp_username']);
         } else {
             printf(__('Logging in as %s without a password...', 'WPMove'), $wpmove_options['ftp_username']);
         }
         $this->flush_output();
         // Login to the server using the supplied credentials
         if ($ftp->login($wpmove_options['ftp_username'], $ftp_password)) {
             echo ' <strong>' . __('Success!', 'WPMove') . '</strong><br>' . __('Starting uploading files...', 'WPMove') . '<br>';
             $this->flush_output();
             // Changes the present working directory to the backup directory on the remote server
             $ftp->chdir($wpmove_options['ftp_remote_path']);
             // Start counting errors during the file upload
             $error_count = 0;
             // Upload the given backup files under the backup folder to the server
             foreach ($files as $file) {
                 printf(__('%s is being uploaded...', 'WPMove'), basename($file));
                 $this->flush_output();
                 if (FALSE !== $ftp->put(trailingslashit(WPMOVE_BACKUP_DIR) . $file, basename($file))) {
                     echo '<strong>' . __(' Success!', 'WPMove') . '</strong><br>';
                 } else {
                     echo '<strong>' . __(' Failed!', 'WPMove') . '</strong><br>';
                     $error_count++;
                 }
                 $this->flush_output();
             }
             // Notify the user about the errors occured
             if ($error_count) {
                 printf(_n('Uploading files is completed with %d error...', 'Uploading files is completed with %d errors...', $error_count, 'WPMove'), $error_count);
             } else {
                 _e('Uploading files is completed without an error...', 'WPMove');
             }
             $this->flush_output();
             echo '<br>';
             _e('Closing the FTP connection...', 'WPMove');
             echo '</span><br>';
             // Close the connection
             $ftp->quit();
             // Return TRUE on success
             return TRUE;
         }
         // Close the connection
         $ftp->quit();
     }
     echo ' <strong>' . __(' Failed!', 'WPMove') . '</strong><br>' . __('Operation terminated...', 'WPMove') . '</span><br>';
     // If it reaches here, apparently it failed
     return FALSE;
 }
Пример #3
0
function ampps_ftp($host, $port, $username, $pass, $cd = false, $pub = '', $pri = '', $passphrase = '')
{
    global $settings;
    if ($settings['protocol'] == 'sftp' && !class_exists('sftp')) {
        include_once '_' . $settings['protocol'] . '.php';
    } elseif ($settings['protocol'] == 'ftps' && !class_exists('ftps')) {
        include_once '_' . $settings['protocol'] . '.php';
    } elseif ($settings['protocol'] == 'ftp' && !class_exists('ftp_base')) {
        include_once '_' . $settings['protocol'] . '.php';
    } elseif ($settings['protocol'] == 'customio' && !class_exists('CustomIO')) {
        include_once '_' . $settings['protocol'] . '.php';
    }
    if ($settings['protocol'] == 'ftp') {
        $ftp = new ftp(FALSE, FALSE);
        if (!$ftp->SetServer($host)) {
            $ftp->quit();
            return 0;
        }
        if (!$ftp->connect()) {
            return -1;
        }
        if (!$ftp->login($username, $pass)) {
            $ftp->quit();
            return -2;
        }
        if (!empty($cd)) {
            if (!$ftp->chdir($cd)) {
                if (!$ftp->chdir(trim($cd, '/'))) {
                    return -3;
                }
                //return -3;
            }
        }
        if (!$ftp->SetType(FTP_AUTOASCII)) {
        }
        if (!$ftp->Passive(TRUE)) {
        }
    }
    if ($settings['protocol'] == 'sftp' || $settings['protocol'] == 'ftps' || $settings['protocol'] == 'customio') {
        if ($settings['protocol'] == 'customio') {
            $ftp = new CustomIO();
        } else {
            $ftp = new $settings['protocol']();
        }
        if ($settings['protocol'] == 'sftp' && !empty($pub) && !empty($pri)) {
            $ftp->auth_pass = 0;
        } else {
            $ftp->auth_pass = 1;
        }
        $ret = $ftp->connect($host, $port, $username, $pass, $pub, $pri, $passphrase);
        if (!is_object($ftp)) {
            return -1;
        }
        if (!$ret) {
            return -2;
        }
        /* if($settings['protocol'] == 'sftp' && (!$ret)){
        			return -2;
        		}
        		
        		if(($settings['protocol'] == 'ftps' || $settings['protocol'] == 'customio') && !$ftp->ftp_conn){
        			return -2;
        		} */
        if (!empty($cd)) {
            if (!$ftp->is_dir($cd)) {
                return -3;
            }
        }
    }
    return $ftp;
}