protected function get_files()
 {
     $server = $this->config->config_data['common']['host'];
     $user = $this->config->config_data['common']['user'];
     $password = $this->config->config_data['common']['password'];
     $directory_remote = rtrim($this->config->config_data['import']['remote_basedir'], '/');
     $directory_local = rtrim($this->config->config_data['import']['local_path'], '/');
     $port = 22;
     if (!function_exists("ssh2_connect")) {
         die("function ssh2_connect doesn't exist");
     }
     if (!($connection = ssh2_connect($server, $port))) {
         echo "fail: unable to establish connection\n";
     } else {
         // try to authenticate with username root, password secretpassword
         if (!ssh2_auth_password($connection, $user, $password)) {
             echo "fail: unable to authenticate\n";
         } else {
             // allright, we're in!
             echo "okay: logged in...<br/>";
             // Enter "sftp" mode
             $sftp = @ssh2_sftp($connection);
             // Scan directory
             $files = array();
             echo "Scanning {$directory_remote}<br/>";
             $dir = "ssh2.sftp://{$sftp}{$directory_remote}";
             $handle = opendir($dir);
             while (false !== ($file = readdir($handle))) {
                 if (is_dir($file)) {
                     echo "Directory: {$file}<br/>";
                     continue;
                 }
                 /*						if ($this->debug)
                 						{
                 							$size = filesize("ssh2.sftp://$sftp$directory_remote/$file");
                 							echo "File $file Size: $size<br/>";
                 
                 							$stream = @fopen("ssh2.sftp://$sftp$directory_remote/$file", 'r');
                 							$contents = fread($stream, filesize("ssh2.sftp://$sftp$directory_remote/$file"));
                 							@fclose($stream);
                 							echo "CONTENTS: $contents<br/><br/>";
                 						}
                 */
                 $files[] = $file;
             }
             if ($this->debug) {
                 _debug_array($files);
             } else {
                 foreach ($files as $file_name) {
                     if (stripos($file_name, 'Px205') === 0) {
                         //		_debug_array($file_name);
                         $file_remote = "{$directory_remote}/{$file_name}";
                         $file_local = "{$directory_local}/{$file_name}";
                         $stream = fopen("ssh2.sftp://{$sftp}{$file_remote}", 'r');
                         $contents = fread($stream, filesize("ssh2.sftp://{$sftp}{$file_remote}"));
                         fclose($stream);
                         $fp = fopen($file_local, "wb");
                         fwrite($fp, $contents);
                         if (fclose($fp)) {
                             echo "File remote: {$file_remote} was copied to local: {$file_local}<br/>";
                             if (ssh2_sftp_unlink($sftp, "{$directory_remote}/archive/{$file_name}")) {
                                 echo "Deleted duplicate File remote: {$directory_remote}/archive/{$file_name}<br/>";
                             }
                             if (ssh2_sftp_rename($sftp, $file_remote, "{$directory_remote}/archive/{$file_name}")) {
                                 echo "File remote: {$file_remote} was moved to remote: {$directory_remote}/archive/{$file_name}<br/>";
                             } else {
                                 echo "ERROR! File remote: {$file_remote} failed to move to remote: {$directory_remote}/archive/{$file_name}<br/>";
                                 if (unlink($file_local)) {
                                     echo "Lokal file was deleted: {$file_local}<br/>";
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Renames a remote file
  *
  * @param  string $from The current file that is being renamed
  * @param  string $to   The new file name that replaces from
  *
  * @return Boolean TRUE on success, or FALSE on failure
  */
 public function rename($from, $to)
 {
     return ssh2_sftp_rename($this->getResource(), $from, $to);
 }
Esempio n. 3
0
 /**
  * Facade for ssh2_sftp_rename.
  *
  * @param resource $resource    The sftp resource to use.
  * @param string   $source_path The remote source path.
  * @param string   $dest_path   The remote destination path.
  *
  * @return boolean True on success.
  */
 public function sftpRename($resource, $source_path, $dest_path)
 {
     return ssh2_sftp_rename($resource, $source_path, $dest_path);
 }
Esempio n. 4
0
 /**
  * Download order files from tb server
  * @return Array of String contain filename that available on tb out folder
  */
 public function downloadOrders()
 {
     use_class('jng_sp_download');
     $class_jd = new jng_sp_download();
     $result = false;
     $target_dir = TRADEBYTE_FTP_OUT_PATH;
     $local_dir = TRADEBYTE_DOWNLOAD_ORDERS_PATH;
     $dir_handle = $this->openDir($target_dir);
     $jng_sp_id = 0;
     //ALL DOWNLOADED ORDERS VIA TRADEBYTE WE USE 0 AS jng_sp_id "ONLY" ON TABLE jng_sp_download
     $download_status_to_generate = 'R';
     while (($file = readdir($dir_handle)) !== false) {
         if ($file != '.' && $file != '..') {
             $downloaded_file = $this->downloadFile($target_dir . $file, $local_dir . $file);
             if ($downloaded_file !== false && $downloaded_file != -1) {
                 $files[] = $downloaded_file;
                 $class_jd->addDownload($jng_sp_id, 'ORDERS', basename($downloaded_file), $download_status_to_generate);
                 $order_done_filename = TRADEBYTE_FTP_ARCHIVE_PATH . $this->getFilePrefixDone() . $file;
                 ssh2_sftp_rename($this->sftp, $target_dir . $file, $order_done_filename);
             }
         }
     }
     if (is_array($files) && count($files) > 0) {
         $result = $files;
     }
     return $result;
 }
Esempio n. 5
0
 /**
  * Remote rename.
  *
  * @param string $from
  * @param string $to
  *
  * @return bool
  */
 public function rename($from, $to)
 {
     ssh2_sftp_rename($this->resource, $from, $to);
 }
Esempio n. 6
0
 /**
  * Rename file in remote server
  */
 public function mv($remoteFile, $newName)
 {
     $from = $this->_getFilename($remoteFile);
     $to = $this->_getFilename($newName);
     if (!ssh2_sftp_rename($this->_getSftp(), $from, $to)) {
         throw new \Exception("Could not rename file '{$from}' as '{$to}'");
     }
 }
Esempio n. 7
0
 /**
  * Moves a file through the backend.
  *
  * @param string $path         The path of the original file.
  * @param string $name         The name of the original file.
  * @param string $dest         The destination file name.
  * @param boolean $autocreate  Auto-create the directory if it doesn't
  *                             exist?
  *
  * @throws Horde_Vfs_Exception
  */
 public function move($path, $name, $dest, $autocreate = false)
 {
     $orig = $this->_getPath($path, $name);
     if (preg_match('|^' . preg_quote($orig) . '/?$|', $dest)) {
         throw new Horde_Vfs_Exception('Cannot move file(s) - destination is within source.');
     }
     $this->_connect();
     if ($autocreate) {
         $this->autocreatePath($dest);
     }
     foreach ($this->listFolder($dest, null, true) as $file) {
         if ($file['name'] == $name) {
             throw new Horde_Vfs_Exception(sprintf('%s already exists.', $this->_getPath($dest, $name)));
         }
     }
     if (!@ssh2_sftp_rename($this->_sftp, $orig, $this->_getPath($dest, $name))) {
         throw new Horde_Vfs_Exception(sprintf('Failed to move to "%s".', $this->_getPath($dest, $name)));
     }
 }
 /**
  * @see Filesystem::doMove
  */
 protected function doMove($source, $destination)
 {
     wfSuppressWarnings();
     $ssh2_sftp_rename = ssh2_sftp_rename($this->connection, $source, $destination);
     wfRestoreWarnings();
     return $ssh2_sftp_rename;
 }
Esempio n. 9
0
 /**
  * @inheritdoc
  */
 public function moveFileInternal($srcFile, $destFile)
 {
     $srcFullFileName = $this->composeFullFileNameByReference($srcFile);
     $destFullFileName = $this->composeFullFileNameByReference($destFile);
     $this->createDirectory(dirname($destFullFileName));
     $result = ssh2_sftp_rename($this->getStorage()->getSftp(), $srcFullFileName, $destFullFileName);
     if ($result) {
         $this->log("file '{$srcFullFileName}' has been moved to '{$destFullFileName}'");
     } else {
         $this->log("unable to move file from '{$srcFullFileName}' to '{$destFullFileName}'!", Logger::LEVEL_ERROR);
     }
     return $result;
 }
Esempio n. 10
0
 /**
  * Rename a file
  *
  * @access	public
  * @param	string
  * @param	string
  * @param	bool
  * @return	bool
  */
 function rename($old_file, $new_file, $move = FALSE)
 {
     if (!$this->_is_conn()) {
         return FALSE;
     }
     $result = @ssh2_sftp_rename($this->conn_sftp, $old_file, $new_file);
     if ($result === FALSE) {
         $this->_error('sftp_unable_to_rename');
         return FALSE;
     }
     return TRUE;
 }
Esempio n. 11
0
 function ssh2Rename($oldsourcefilename, $newsourcefilename)
 {
     $result = ssh2_sftp_rename($this->sftp, $oldsourcefilename, $newsourcefilename);
     return $result;
 }
Esempio n. 12
0
 /**
  * [rename description]
  * @param  [type] $oldFile [description]
  * @param  [type] $newFile [description]
  * @return [type]          [description]
  */
 public function move($oldFile, $newFile)
 {
     if (false === $this->validConn()) {
         throw new Exception('invalid connection');
     }
     if (!($this->sftp = @ssh2_sftp($this->conn))) {
         throw new Exception("unable to establish sftp connection with {$host}");
     }
     return $this->sftp;
     if (false === ($result = @ssh2_sftp_rename($this->sftp, $oldFile, $newFile))) {
         throw new Exception("unable to rename file");
     }
     return $result;
 }
Esempio n. 13
0
 /**
  * {@inheritdoc}
  */
 public function rename(BucketInterface $bucket, $oldname, $newname)
 {
     if (!$this->exists($bucket, $oldname)) {
         throw new ServerException("Unable to rename storage object '{$oldname}', object does not exists at SFTP server.");
     }
     $location = $this->ensureLocation($bucket, $newname);
     if (file_exists($this->getUri($bucket, $newname))) {
         //We have to clean location before renaming
         $this->delete($bucket, $newname);
     }
     if (!ssh2_sftp_rename($this->sftp, $this->getPath($bucket, $oldname), $location)) {
         throw new ServerException("Unable to rename storage object '{$oldname}' to '{$newname}'.");
     }
     return $this->refreshPermissions($bucket, $newname);
 }
Esempio n. 14
0
 public function mv($from, $to)
 {
     return ssh2_sftp_rename($this->_sftp, $from, $to);
 }
Esempio n. 15
0
 public function rename($source, $destination)
 {
     return @ssh2_sftp_rename($this->handle, $source, $destination);
 }
Esempio n. 16
0
 public function rename(string $oldName, string $newName) : bool
 {
     if (@ssh2_sftp_rename($this->connect, $oldName, $newName)) {
         return true;
     } else {
         throw new FolderChangeNameException($oldName);
     }
 }
Esempio n. 17
0
 /**
  * @param string $oldIdentifier
  * @param string $newIdentifier
  * @return bool
  */
 public function rename($oldIdentifier, $newIdentifier)
 {
     $this->delete($newIdentifier, false);
     if (ssh2_sftp_rename($this->sftp, $oldIdentifier, $newIdentifier)) {
         return true;
     } else {
         $this->delete($oldIdentifier, false);
         return false;
     }
 }
Esempio n. 18
0
 /**
  * Facade for ssh2_sftp_rename.
  *
  * @param resource $resource    The sftp resource to use.
  * @param string   $source_path The remote source path.
  * @param string   $dest_path   The remote destination path.
  *
  * @return boolean True on success.
  */
 public function sftpRename($resource, $source_path, $dest_path)
 {
     //@codeCoverageIgnoreStart
     return ssh2_sftp_rename($resource, $source_path, $dest_path);
     //@codeCoverageIgnoreEnd
 }
Esempio n. 19
0
 /**
  * Renames a remote file.
  *
  * @param string $old_name
  * @param string $new_name
  *
  * @return boolean Returns TRUE on success or FALSE on error
  *
  * @throws \BackBee\Util\Transport\Exception\TransportException Occures if SSH connection is invalid
  */
 public function rename($old_name, $new_name)
 {
     if (null === $this->_sftp_resource) {
         throw new TransportException(sprintf('None SSH connection available.'));
     }
     $old_name = $this->_getAbsoluteRemotePath($old_name);
     $new_name = $this->_getAbsoluteRemotePath($new_name);
     if (false === @ssh2_sftp_stat($this->_sftp_resource, $old_name)) {
         return $this->_trigger_error(sprintf('Could not open remote file: %s.', $old_name));
     }
     if (false !== @ssh2_sftp_stat($this->_sftp_resource, $new_name)) {
         return $this->_trigger_error(sprintf('Remote file already exists: %s.', $new_name));
     }
     if (false === @ssh2_sftp_rename($this->_sftp_resource, $old_name, $new_name)) {
         return $this->_trigger_error(sprintf('Unable to rename %s to %s', $old_name, $new_name));
     }
     return true;
 }
Esempio n. 20
0
 /**
  * Rename (or move) a file
  *
  * @version 1.0
  * @access  public
  * @param   string
  * @param   string
  * @param   bool
  * @return  bool
  */
 public function rename($old_file, $new_file, $move = FALSE)
 {
     if (!$this->_is_conn()) {
         return FALSE;
     }
     $result = @ssh2_sftp_rename($this->sftp, $old_file, $new_file);
     if ($result === FALSE) {
         if ($this->debug == TRUE) {
             $msg = $move == FALSE ? 'ftp_unable_to_rename' : 'ftp_unable_to_move';
             $this->_error($msg);
         }
         return FALSE;
     }
     return TRUE;
 }
Esempio n. 21
0
 public function rename($from, $to)
 {
     $from = '/' . trim($this->dir, '/') . '/' . trim($from, '/');
     $to = '/' . trim($this->dir, '/') . '/' . trim($to, '/');
     $result = @ssh2_sftp_rename($this->handle, $from, $to);
     if ($result !== true) {
         return @rename($from, $to);
     } else {
         return true;
     }
 }
Esempio n. 22
0
 /**
  * sftp_rename_file($fileContainer, $new_name)
  * 
  * The function renames a file already located on one or
  * more SFTP servers with a new image.
  *
  */
 function sftp_rename_file($fileContainer, $new_name_relative)
 {
     $sql = "SELECT * FROM {$this->config['TABLE_SFTP_SERVERS']} JOIN {$this->config['TABLE_SFTP_PIC2SERVER']} ON {$this->config['TABLE_SFTP_SERVERS']}.id={$this->config['TABLE_SFTP_PIC2SERVER']}.server_id WHERE {$this->config['TABLE_SFTP_PIC2SERVER']}.pic_id='{$fileContainer->id}' AND {$this->config['TABLE_SFTP_SERVERS']}.status!='inactive'";
     $result = cpg_db_query($sql);
     while ($server = mysql_fetch_assoc($result)) {
         $conn_id = $this->get_sftp_connection_id($server);
         // this queries the open connections list for the right $conn_id.
         $old_name = $server['root_path'] . $fileContainer->original_path;
         $new_name = $server['root_path'] . $new_name_relative;
         ssh2_sftp_rename($conn_id, $old_name, $new_name);
     }
     return true;
 }
Esempio n. 23
0
 /**
  * @{inheritDoc}
  */
 public function rename($from = '', $to = '')
 {
     return $this->doRun(__METHOD__, func_get_args(), ssh2_sftp_rename($this->sftp, $from, $to));
 }
Esempio n. 24
0
 public function move($oldPath, $newPath)
 {
     $oldPath = $this->path($oldPath);
     $newPath = $this->path($newPath);
     $return = @ssh2_sftp_rename($this->getSftpResource(), $oldPath, $newPath);
     if (!$return) {
         throw new Engine_Vfs_Adapter_Exception(sprintf('Unable to rename "%s" to "%s"', $oldPath, $newPath));
     }
     return true;
 }
Esempio n. 25
0
 function move($source, $destination, $overwrite = false)
 {
     return @ssh2_sftp_rename($this->link, $source, $destination);
 }
Esempio n. 26
0
 /**
  * Renames a remote file
  *
  * @param string $from the current file that is being renamed
  * @param string $to the new file name that replaces
  * @return bool TRUE on success or FALSE on failure
  */
 public function rename($from, $to)
 {
     $this->connect();
     return @ssh2_sftp_rename($this->_sftp, $from, $to);
 }