public function connect() { // we have to mangle the include path a little to find our plugins $oldIncludePath = get_include_path(); set_include_path($oldIncludePath . ':' . TL_ROOT . '/plugins/phpseclib/:' . TL_ROOT . '/plugins/phpseclib/Net:' . TL_ROOT . '/plugins/phpseclib/Crypt'); include 'SFTP.php'; if ($GLOBALS['TL_CONFIG']['sftpKeyFile']) { include 'RSA.php'; } set_include_path($oldIncludePath); $this->ftpHost = $GLOBALS['TL_CONFIG']['ftpHost']; $this->ftpPort = $GLOBALS['TL_CONFIG']['ftpPort']; $this->ftpUser = $GLOBALS['TL_CONFIG']['ftpUser']; if ($GLOBALS['TL_CONFIG']['sftpKeyFile']) { $key = new Crypt_RSA(); if ($GLOBALS['TL_CONFIG']['sftpKeyPass']) { $key->setPassword($GLOBALS['TL_CONFIG']['sftpKeyPass']); } $key->loadKey(file_get_contents($GLOBALS['TL_CONFIG']['sftpKeyFile'])); $this->ftpPass = $key; } else { $this->ftpPass = $GLOBALS['TL_CONFIG']['ftpPass']; } $this->ftpPath = $GLOBALS['TL_CONFIG']['ftpPath']; // Connect to FTP server if (!is_numeric($this->ftpPort) || $this->ftpPort == 0) { $this->ftpPort = 22; } if ($GLOBALS['TL_CONFIG']['debugSmhExtended']) { define('NET_SSH2_LOGGING', true); define('NET_SFTP_LOGGING', true); } if (($resConnection = new Net_SFTP($this->ftpHost, $this->ftpPort, 5)) != false) { // Login if (!$resConnection->login($this->ftpUser, $this->ftpPass)) { throw new Exception('Could not login to sftp: ' . $resConnection->getLastError() . (defined('NET_SSH2_LOGGING') ? implode("\n", $resConnection->message_number_log) : '')); } // security, clean user id and password as we won't need them anymore. $this->ftpUser = NULL; $this->ftpPass = NULL; // change to root directory to ensure we can really work. $resConnection->chdir($this->ftpPath); $this->resConnection = $resConnection; return $resConnection; } else { throw new Exception('Could not connect to sftp: ' . $resConnection->getLastError()); } }
public function getError() { $err = $this->ftp->getLastError(); if (!$err) { $err = $this->ftp->getLastSFTPError(); } if ($err) { return $err['msg']; } }