コード例 #1
0
function escribe_archivo_via_sftp($cadena, $nombre_archivo_remoto = "", $factura_id, $fe_folio)
{
    $sql_update = "update vta_p_facturas set \n\tFE_SERIE='A', FE_FOLIO={$fe_folio}\n\twhere (FE_SERIE = '' OR FE_SERIE IS NULL or FE_SERIE=0) AND (FE_FOLIO = '' OR FE_FOLIO IS NULL or FE_FOLIO =0) \n\tAND FACTURA_ID=" . $factura_id;
    $result_update = mysql_db_query(DB_NAME, $sql_update);
    // echo $sql_update;
    define("TEPath", "../TableEditor/");
    include '../TableEditor/Net/SFTP.php';
    //  $ftp_sitio="demo-partners.xsa.com.mx";
    //  $ftp_usuario="testftpfacciisa";
    //  $ftp_pass="******";
    $ftp_sitio = "173.205.255.84";
    $ftp_usuario = "ftpciisa";
    $ftp_pass = "******";
    $sftp = new Net_SFTP($ftp_sitio);
    if (!$sftp->login($ftp_usuario, $ftp_pass)) {
        exit('Acceso incorrecto..');
    }
    $sftp->put($nombre_archivo_remoto, utf8_encode($cadena));
    $sftp->chdir("1");
    $sftp->put($nombre_archivo_remoto, utf8_encode($cadena));
    $folio_fiscal = consulta("select FOLIO_FISCAL from vta_p_facturas WHERE FACTURA_ID=" . $factura_id);
    $folio_fiscal = $folio_fiscal["FOLIO_FISCAL"];
    //echo $fe_serie["FE_FOLIO"]."+";
    echo "Envio exitoso... Factura " . $folio_fiscal;
}
コード例 #2
0
ファイル: CSFTP.class.php プロジェクト: fbone/mediboard4
 /**
  * Change the directory to the target directory
  *
  * @param String $directory directory path
  *
  * @return bool
  * @throws CMbException
  */
 private function _changeDirectory($directory)
 {
     if (!$this->connexion) {
         throw new CMbException("CSourceSFTP-connexion-failed", $this->hostname);
     }
     if (!($chdir = $this->connexion->chdir($directory))) {
         throw new CMbException("CSourceSFTP-change-directory-failed", $directory);
     }
     return true;
 }
コード例 #3
0
ファイル: Sftp.php プロジェクト: CE-Webmaster/CE-Hub
 /**
  * @param array $config
  *
  * @throws Mageplace_Backup_Exception|Mage_Core_Exception
  * @return Net_SFTP
  */
 public function getSftp(array $config = array())
 {
     if ($this->_getData('sftp') === null) {
         $host = $this->getConfigValue(self::HOST);
         $port = (int) $this->getConfigValue(self::PORT);
         if ($port <= 0) {
             $port = self::DEFAULT_PORT;
         }
         $sftp = new Net_SFTP($host, $port, $this->getTimeOut());
         if (!$sftp->login($this->getConfigValue(self::USERNAME), $this->getConfigValue(self::PASSWORD))) {
             $this->_throwExeption($this->_helper->__("SFTP connection error: unable to open connection as %s@%s:%d", $this->getConfigValue(self::USERNAME), $host, $port));
         }
         if ($path = rtrim($this->getConfigValue(self::PATH), '/')) {
             if (!$sftp->chdir($path)) {
                 $this->_throwExeption($this->_helper->__('SFTP connection error: invalid path'));
             }
         }
         $this->setData('sftp', $sftp);
     }
     return $this->_getData('sftp');
 }
コード例 #4
0
 function get_ftp_backup($args, $current_file_num = 0)
 {
     extract($args);
     if (isset($use_sftp) && $use_sftp == 1) {
         $port = $ftp_port ? $ftp_port : 22;
         //default port is 22
         /*
          * SFTP section start here phpseclib library is used for this functionality
          */
         $iwp_mmb_plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
         $path = $iwp_mmb_plugin_dir . '/lib/phpseclib';
         set_include_path(get_include_path() . PATH_SEPARATOR . $path);
         include_once 'Net/SFTP.php';
         $sftp = new Net_SFTP($ftp_hostname, $port);
         if (!$sftp) {
             return array('error' => 'Failed to connect to ' . $ftp_hostname, 'partial' => 1);
         }
         if (!$sftp->login($ftp_username, $ftp_password)) {
             return array('error' => 'FTP login failed for ' . $ftp_username . ', ' . $ftp_password, 'partial' => 1);
         } else {
             if ($ftp_site_folder) {
                 $ftp_remote_folder .= '/' . $this->site_name;
             }
             $remote_loation = basename($backup_file);
             $local_location = $backup_file;
             $sftp->chdir($ftp_remote_folder);
             //$sftp->delete(basename($backup_file));
             $temp = wp_tempnam('iwp_temp_backup.zip');
             $get = $sftp->get(basename($backup_file), $temp);
             if ($get === false) {
                 return false;
             } else {
                 return $temp;
             }
             //SFTP library has automatic connection closed. So no need to call seperate connection close function
         }
     } else {
         //Args: $ftp_username, $ftp_password, $ftp_hostname, $backup_file, $ftp_remote_folder
         $port = $ftp_port ? $ftp_port : 21;
         //default port is 21
         if ($ftp_ssl && function_exists('ftp_ssl_connect')) {
             $conn_id = ftp_ssl_connect($ftp_hostname, $port);
         } else {
             if (function_exists('ftp_connect')) {
                 $conn_id = ftp_connect($ftp_hostname, $port);
                 if ($conn_id === false) {
                     return false;
                 }
             }
         }
         $login = @ftp_login($conn_id, $ftp_username, $ftp_password);
         if ($login === false) {
             return false;
         }
         if ($ftp_site_folder) {
             $ftp_remote_folder .= '/' . $this->site_name;
         }
         if ($ftp_passive) {
             @ftp_pasv($conn_id, true);
         }
         //$temp = ABSPATH . 'iwp_temp_backup.zip';
         $temp = wp_tempnam('iwp_temp_backup.zip');
         $get = ftp_get($conn_id, $temp, $ftp_remote_folder . '/' . $backup_file, FTP_BINARY);
         if ($get === false) {
             return false;
         } else {
         }
         ftp_close($conn_id);
         return $temp;
     }
 }
コード例 #5
0
ファイル: Sftp.php プロジェクト: Airmal/Magento-Em
 /**
  * Change current working directory
  *
  */
 public function cd($dir)
 {
     return $this->_connection->chdir($dir);
 }
コード例 #6
0
ファイル: _manage.php プロジェクト: elephantcode/elephantcode
     // Handle custom sFTP port.
     $server_params = explode(':', $server);
     $server = $server_params[0];
     $port = $server_params[1];
 }
 pb_backupbuddy::status('details', 'Connecting to sFTP server...');
 $sftp = new Net_SFTP($server, $port);
 if (!$sftp->login($destination['username'], $destination['password'])) {
     pb_backupbuddy::status('error', 'Connection to sFTP server FAILED.');
     return false;
 } else {
     pb_backupbuddy::status('details', 'Success connecting to sFTP server.');
 }
 // Change to directory.
 pb_backupbuddy::status('details', 'Attempting to change into directory...');
 if (true === $sftp->chdir($destination['path'])) {
     pb_backupbuddy::status('details', 'Changed into directory.');
 } else {
     pb_backupbuddy::status('error', 'Unable to change into specified path. Verify the path is correct with valid permissions.');
     return false;
 }
 // loop through and delete ftp backup files
 foreach ((array) pb_backupbuddy::_POST('items') as $backup) {
     // try to delete backup
     if (true === $sftp->delete($backup)) {
         $delete_count++;
     } else {
         pb_backupbuddy::alert('Unable to delete file `' . $destination['path'] . '/' . $backup . '`.');
     }
 }
 if ($delete_count > 0) {
コード例 #7
0
	exit(0);
}*/
//if(file_exists($encryptedFileName))
if (file_exists($localfilename)) {
    include "Net/SFTP.php";
    $ftp_server = 'PDCFTP.cvty.com';
    $ftp_user = '******';
    $ftp_password = '******';
    $ftp_port = '21000';
    $ftp_directory = '/Incoming/';
    //'/Test/Incoming/'
    $sftp = new Net_SFTP($ftp_server, $ftp_port);
    // FTP Login
    if ($sftp->login($ftp_user, $ftp_password)) {
        // Change directory
        if ($sftp->chdir($ftp_directory)) {
            if ($sftp->put($remoteFileName, $localfilename, NET_SFTP_LOCAL_FILE)) {
                $destFileName = str_replace('C:\\Inetpub\\wwwroot\\plexis\\php\\', 'D:\\Documents\\Misc\\' . $clientName . "_", $savePathAndFileName);
                //echo "destFileName:  ".$destFileName."\n";
                //echo "localfilename:  ".$localfilename."\n";
                //echo "remoteFileName:  ".$remoteFileName."\n";
                if (file_exists($destFileName)) {
                    unlink($destFileName);
                }
                rename($localfilename, $destFileName);
            } else {
                $msg = "Unable to put " . $localfilename . " file to [" . $ftp_server . "] /" . $ftp_directory . "/" . $remoteFileName . "<br/>";
            }
        } else {
            $msg = "chdir failed to [" . $ftp_server . "] " . $ftp_directory;
        }
コード例 #8
0
ファイル: cron.php プロジェクト: xiaokangrj/cdp
 if (strpos($verifyvzdump, 'command not found') !== false) {
     $log .= 'vzdump command not found' . PHP_EOL;
     exitcron();
 } else {
     $log .= 'vzdump detected' . PHP_EOL;
 }
 $verifyproxmox = $ssh->exec(escapeshellcmd('pveversion -v'));
 if (strpos($verifyproxmox, 'pve-manager') !== false) {
     $log .= 'ProxMox detected' . PHP_EOL;
     $isproxmox = true;
 } else {
     $log .= 'Standard OpenVZ detected' . PHP_EOL;
     $isproxmox = false;
 }
 $log .= $ssh->exec(escapeshellcmd('mkdir /tmp/' . $dirname)) . PHP_EOL;
 $sftp->chdir('/tmp/' . $dirname);
 $containers = $ssh->exec(escapeshellcmd('vzlist -jao ctid'));
 $containers = json_decode($containers, true);
 $donotbackup = explode(' ', $backupjob['directory']);
 $containerstobackup = array();
 foreach ($containers as $container) {
     if (!in_array($container['ctid'], $donotbackup)) {
         $containerstobackup[count($containerstobackup)] = $container['ctid'];
     }
 }
 foreach ($containerstobackup as $container) {
     $log .= 'Backing up CT ' . $container . PHP_EOL;
     $vzstarttime = time();
     if ($isproxmox) {
         $log .= $ssh->exec(escapeshellcmd('vzdump -mode snapshot -compress gzip -dumpdir /tmp/' . $dirname . ' ' . $container)) . PHP_EOL;
         $log .= $ssh->exec(escapeshellcmd('mv vzdump-openvz-*.tgz vzdump-' . $container . '.tgz')) . PHP_EOL;
コード例 #9
0
ファイル: restore.php プロジェクト: xiaokangrj/cdp
         die('SSH key login failed');
     }
     if (!$sftp->login($backupserver['username'], $key)) {
         die('SFTP key login failed');
     }
 } else {
     die('SSH login failed');
 }
 $verifyvzdump = $ssh->exec(escapeshellcmd('vzdump'));
 if (strpos($verifyvzdump, 'command not found') !== false) {
     echo 'vzdump command not found' . PHP_EOL;
     die;
 } else {
     echo 'vzdump detected' . PHP_EOL;
 }
 echo $sftp->chdir('/');
 if (isset($backupjob['encryption']) && $backupjob['encryption'] == 'AES-256') {
     echo 'Decrypting file with AES-256' . PHP_EOL;
     $cipher = new Crypt_AES(CRYPT_AES_MODE_ECB);
     $cipher->setKey($backupjob['encryptionkey']);
     file_put_contents($config['path'] . '/files/' . $argv[1] . '.decrypted', $cipher->decrypt(file_get_contents($config['path'] . '/files/' . $argv[1])));
     echo 'Transferring the file' . PHP_EOL;
     echo $sftp->put($argv[1], $config['path'] . '/files/' . $argv[1] . '.decrypted', NET_SFTP_LOCAL_FILE);
     unlink($config['path'] . '/files/' . $argv[1] . '.decrypted');
 } else {
     echo 'Transferring the file' . PHP_EOL;
     echo $sftp->put($argv[1], $config['path'] . '/files/' . $argv[1], NET_SFTP_LOCAL_FILE);
 }
 $ctid = explode('vzdump-', trim($argv[1]));
 $ctid = explode('.tgz', $ctid[1]);
 echo $ssh->exec(escapeshellcmd('vzctl stop ' . $ctid[0]));
コード例 #10
0
<?php

include_once '../settings/autoload.php';
$msql = SafeMySQL::getInstance();
$sftp = new Net_SFTP(PSGlobalCollect::FTP_URL);
if (!$sftp->login(PSGlobalCollect::FTP_LOGIN, PSGlobalCollect::FTP_PASSWORD)) {
    exit('Login Failed');
}
$sftp->chdir('out');
$files = $sftp->nlist();
$wr1 = array();
foreach ($files as $filename) {
    if (substr($filename, 0, 4) == '7760' && substr($filename, -4) == '.wr1') {
        $wr1[] = $filename;
    }
}
sort($wr1);
foreach ($wr1 as $filename) {
    echo $filename . '<br />';
    $sql = "SELECT * FROM `wr1` WHERE `filename` = ?s";
    $result = $msql->query($sql, substr($filename, 0, 8));
    if (!$result->num_rows) {
        $wr1File = $sftp->get($filename);
        if (strlen($wr1File) != 802) {
            preg_match_all('/^.{3}7760.{43}LJ(\\d+).*$/m', $wr1File, $matches);
            $orderIDs = array_unique($matches[1]);
            sort($orderIDs);
            $ordersArr = array();
            foreach ($orderIDs as $order) {
                $ordersArr[] = '(' . (int) $order . ')';
            }
コード例 #11
0
 function remove_ftp_backup($args)
 {
     extract($args);
     //Args: $ftp_username, $ftp_password, $ftp_hostname, $backup_file, $ftp_remote_folder
     if (isset($use_sftp) && $use_sftp == 1) {
         $port = $ftp_port ? $ftp_port : 22;
         //default port is 22
         /*
          * SFTP section start here phpseclib library is used for this functionality
          */
         $iwp_mmb_plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
         $path = $iwp_mmb_plugin_dir . '/lib/phpseclib';
         set_include_path(get_include_path() . PATH_SEPARATOR . $path);
         include_once 'Net/SFTP.php';
         $sftp = new Net_SFTP($ftp_hostname, $port);
         if (!$sftp) {
             return array('error' => 'Failed to connect to ' . $ftp_hostname, 'partial' => 1);
         }
         if (!$sftp->login($ftp_username, $ftp_password)) {
             return array('error' => 'FTP login failed for ' . $ftp_username . ', ' . $ftp_password, 'partial' => 1);
         } else {
             if ($ftp_site_folder) {
                 $ftp_remote_folder .= '/' . $this->site_name;
             }
             $remote_loation = basename($backup_file);
             $local_location = $backup_file;
             $sftp->chdir($ftp_remote_folder);
             $sftp->delete(basename($backup_file));
         }
         //SFTP library has automatic connection closed. So no need to call seperate connection close function
     } else {
         $port = $ftp_port ? $ftp_port : 21;
         //default port is 21
         if ($ftp_ssl && function_exists('ftp_ssl_connect')) {
             $conn_id = ftp_ssl_connect($ftp_hostname, $port);
         } else {
             if (function_exists('ftp_connect')) {
                 $conn_id = ftp_connect($ftp_hostname, $port);
             }
         }
         if ($conn_id) {
             $login = @ftp_login($conn_id, $ftp_username, $ftp_password);
             if ($ftp_site_folder) {
                 $ftp_remote_folder .= '/' . $this->site_name;
             }
             if ($ftp_passive) {
                 @ftp_pasv($conn_id, true);
             }
             if (!is_array($backup_file)) {
                 $temp_backup_file = $backup_file;
                 $backup_file = array();
                 $backup_file[] = $temp_backup_file;
             }
             foreach ($backup_file as $key => $value) {
                 $delete = ftp_delete($conn_id, $ftp_remote_folder . '/' . $value);
             }
             ftp_close($conn_id);
         }
     }
 }
コード例 #12
0
 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());
     }
 }
コード例 #13
0
ファイル: SFTPAdapter.php プロジェクト: filicious/sftp
 /**
  * @return \Net_SFTP
  * @throws \Exception
  */
 protected function getConnection()
 {
     if (!$this->connection) {
         $host = $this->config->get(FilesystemConfig::HOST);
         $port = $this->config->get(FilesystemConfig::PORT, 22);
         $username = $this->config->get(FilesystemConfig::USERNAME);
         $password = $this->config->get(FilesystemConfig::PASSWORD, '');
         $key = $this->config->get(self::CONFIG_KEY);
         $keyFile = $this->config->get(self::CONFIG_KEY_FILE);
         $basepath = Util::normalizePath('/' . $this->config->get(FilesystemConfig::BASEPATH, ''));
         if ($keyFile) {
             $key = file_get_contents($keyFile);
         }
         if ($key) {
             $key = new \Crypt_RSA();
             if ($password) {
                 $key->setPassword($password);
             }
             $key->loadKey($key);
             $password = $key;
         }
         $connection = new \Net_SFTP($host, $port);
         if (!$connection->login($username, $password)) {
             throw new \Exception(sprintf('Could not login to %s', $host));
         }
         if ($basepath != '/') {
             $connection->chdir($basepath);
         }
         $this->connection = $connection;
         $this->basepath = $connection->pwd() . '/';
     }
     return $this->connection;
 }
コード例 #14
0
ファイル: init.php プロジェクト: elephantcode/elephantcode
 public static function send($settings = array(), $files = array(), $send_id = '')
 {
     global $pb_backupbuddy_destination_errors;
     if ('1' == $settings['disabled']) {
         $pb_backupbuddy_destination_errors[] = __('Error #48933: This destination is currently disabled. Enable it under this destination\'s Advanced Settings.', 'it-l10n-backupbuddy');
         return false;
     }
     if (!is_array($files)) {
         $files = array($files);
     }
     pb_backupbuddy::status('details', 'FTP class send() function started.');
     self::_init();
     // Connect to server.
     $server = $settings['address'];
     $port = '22';
     // Default sFTP port.
     if (strstr($server, ':')) {
         // Handle custom sFTP port.
         $server_params = explode(':', $server);
         $server = $server_params[0];
         $port = $server_params[1];
     }
     pb_backupbuddy::status('details', 'Connecting to sFTP server...');
     $sftp = new Net_SFTP($server, $port);
     if (!$sftp->login($settings['username'], $settings['password'])) {
         pb_backupbuddy::status('error', 'Connection to sFTP server FAILED.');
         pb_backupbuddy::status('details', 'sFTP log (if available & enabled via full logging mode): `' . $sftp->getSFTPLog() . '`.');
         return false;
     } else {
         pb_backupbuddy::status('details', 'Success connecting to sFTP server.');
     }
     pb_backupbuddy::status('details', 'Attempting to create path (if it does not exist)...');
     if (true === $sftp->mkdir($settings['path'])) {
         // Try to make directory.
         pb_backupbuddy::status('details', 'Directory created.');
     } else {
         pb_backupbuddy::status('details', 'Directory not created.');
     }
     // Change to directory.
     pb_backupbuddy::status('details', 'Attempting to change into directory...');
     if (true === $sftp->chdir($settings['path'])) {
         pb_backupbuddy::status('details', 'Changed into directory `' . $settings['path'] . '`. All uploads will be relative to this.');
     } else {
         pb_backupbuddy::status('error', 'Unable to change into specified path. Verify the path is correct with valid permissions.');
         pb_backupbuddy::status('details', 'sFTP log (if available & enabled via full logging mode): `' . $sftp->getSFTPLog() . '`.');
         return false;
     }
     // Upload files.
     $total_transfer_size = 0;
     $total_transfer_time = 0;
     foreach ($files as $file) {
         if (!file_exists($file)) {
             pb_backupbuddy::status('error', 'Error #859485495. Could not upload local file `' . $file . '` to send to sFTP as it does not exist. Verify the file exists, permissions of file, parent directory, and that ownership is correct. You may need suphp installed on the server.');
         }
         if (!is_readable($file)) {
             pb_backupbuddy::status('error', 'Error #8594846548. Could not read local file `' . $file . '` to send to sFTP as it is not readable. Verify permissions of file, parent directory, and that ownership is correct. You may need suphp installed on the server.');
         }
         $filesize = filesize($file);
         $total_transfer_size += $filesize;
         $destination_file = basename($file);
         pb_backupbuddy::status('details', 'About to put to sFTP local file `' . $file . '` of size `' . pb_backupbuddy::$format->file_size($filesize) . '` to remote file `' . $destination_file . '`.');
         $send_time = -microtime(true);
         $upload = $sftp->put($destination_file, $file, NET_SFTP_LOCAL_FILE);
         $send_time += microtime(true);
         $total_transfer_time += $send_time;
         if ($upload === false) {
             // Failed sending.
             $error_message = 'ERROR #9012b ( http://ithemes.com/codex/page/BackupBuddy:_Error_Codes#9012 ).  sFTP file upload failed. Check file permissions & disk quota.';
             pb_backupbuddy::status('error', $error_message);
             backupbuddy_core::mail_error($error_message);
             pb_backupbuddy::status('details', 'sFTP log (if available & enabled via full logging mode): `' . $sftp->getSFTPLog() . '`.');
             return false;
         } else {
             // Success sending.
             pb_backupbuddy::status('details', 'Success completely sending `' . basename($file) . '` to destination.');
             // Start remote backup limit
             if ($settings['archive_limit'] > 0) {
                 pb_backupbuddy::status('details', 'Archive limit enabled. Getting contents of backup directory.');
                 $contents = $sftp->rawlist($settings['path']);
                 // already in destination directory/path.
                 // Create array of backups
                 $bkupprefix = backupbuddy_core::backup_prefix();
                 $backups = array();
                 foreach ($contents as $filename => $backup) {
                     // check if file is backup
                     $pos = strpos($filename, 'backup-' . $bkupprefix . '-');
                     if ($pos !== FALSE) {
                         $backups[] = array('file' => $filename, 'modified' => $backup['mtime']);
                     }
                 }
                 function backupbuddy_number_sort($a, $b)
                 {
                     return $a['modified'] < $b['modified'];
                 }
                 // Sort by modified using custom sort function above.
                 usort($backups, 'backupbuddy_number_sort');
                 if (count($backups) > $settings['archive_limit']) {
                     pb_backupbuddy::status('details', 'More backups found (' . count($backups) . ') than limit permits (' . $settings['archive_limit'] . ').' . print_r($backups, true));
                     $delete_fail_count = 0;
                     $i = 0;
                     foreach ($backups as $backup) {
                         $i++;
                         if ($i > $settings['archive_limit']) {
                             if (false === $sftp->delete($settings['path'] . '/' . $backup['file'])) {
                                 pb_backupbuddy::status('details', 'Unable to delete excess sFTP file `' . $backup['file'] . '` in path `' . $settings['path'] . '`.');
                                 $delete_fail_count++;
                             } else {
                                 pb_backupbuddy::status('details', 'Deleted excess sFTP file `' . $backup['file'] . '` in path `' . $settings['path'] . '`.');
                             }
                         }
                     }
                     if ($delete_fail_count != 0) {
                         backupbuddy_core::mail_error(sprintf(__('sFTP remote limit could not delete %s backups. Please check and verify file permissions.', 'it-l10n-backupbuddy'), $delete_fail_count));
                         pb_backupbuddy::status('error', 'Unable to delete one or more excess backup archives. File storage limit may be exceeded. Manually clean up backups and check permissions.');
                     } else {
                         pb_backupbuddy::status('details', 'No problems encountered deleting excess backups.');
                     }
                 } else {
                     pb_backupbuddy::status('details', 'Not enough backups found to exceed limit. Skipping limit enforcement.');
                 }
             } else {
                 pb_backupbuddy::status('details', 'No sFTP archive file limit to enforce.');
             }
             // End remote backup limit
         }
     }
     // end $files loop.
     // Load destination fileoptions.
     pb_backupbuddy::status('details', 'About to load fileoptions data.');
     require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
     pb_backupbuddy::status('details', 'Fileoptions instance #6.');
     $fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt', $read_only = false, $ignore_lock = false, $create_file = false);
     if (true !== ($result = $fileoptions_obj->is_ok())) {
         pb_backupbuddy::status('error', __('Fatal Error #9034.843498. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
         return false;
     }
     pb_backupbuddy::status('details', 'Fileoptions data loaded.');
     $fileoptions =& $fileoptions_obj->options;
     // Save stats.
     $fileoptions['write_speed'] = $total_transfer_size / $total_transfer_time;
     $fileoptions_obj->save();
     unset($fileoptions_obj);
     return true;
 }
コード例 #15
0
ファイル: PwSftpSave.php プロジェクト: fanqimeng/4tweb
 public function changeDir($dir)
 {
     return $this->conn->chdir($dir);
 }
コード例 #16
0
 public function chdir($dir)
 {
     return $this->ftp->chdir($dir);
 }
コード例 #17
0
$filename = $filePath;
//silverpop returns filename, not actual path.
$filepath = $sftp_url . '/' . $sftp_dir . '/' . $filename;
//only used in message
//SK 20140227 Needs a $file to attach or a $filepath
//memory stuff: contents of file max 64kb, see also file_get_contents or use output buffering (ob_start)
$file = null;
if (!empty($filename)) {
    //SK 2014028 uses phpseclib, see includes at the top.
    $sftp = new Net_SFTP($sftp_url);
    if (!$sftp->login($sftp_user, $sftp_pass)) {
        exit('Login Failed');
    }
    //change directory
    if (!empty($sftp_dir)) {
        $sftp->chdir($sftp_dir);
    }
    echo "\n--Made sftp connection \n";
    if (empty($mail_to)) {
        //save on server - Check permissions & security
        //$file = $sftp->get($filename, $filename);
        //	//get contents of local file and use those
        //if (!empty($file)) $att_contents = file_get_contents($filename);
        //$file = $att_contents;
        //if (file_exists($filename)) unlink($filename); //try to remove local file
        echo "No e-mail address found to send the file to. The file is stored on the SFTP server ({$filepath}).";
    } else {
        //save in string
        $file = $sftp->get($filename);
        if (empty($file)) {
            echo $sftp->getSFTPLog();