/** * * @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; }
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; }