@param string $fromFilename
@param string $toFilename

@throws UserMessageException
437745
private function decodeGzip($fromFilename, $toFilename)
    {
        if (!function_exists('gzopen')) {
            throw new UserMessageException(t(/*i18n: %s is a compression method, like gzip*/'The PHP zlib extension is required in order to decode "%s" encodings.', 'gzip'));
        }
        try {
            $hFrom = @gzopen($fromFilename, 'rb');
            if ($hFrom === false) {
                throw new UserMessageException(t('Failed to open the file to be decoded with gzip.'));
            }
            $hTo = @fopen($toFilename, 'wb');
            if ($hTo === false) {
                throw new UserMessageException(t('Failed to create the file that contain gzip-decoded data.'));
            }
            while (!gzeof($hFrom)) {
                $data = @gzread($hFrom, 32768);
                if (!is_string($data) || $data === '') {
                    throw new UserMessageException(t('Failed to decode the gzip data.'));
                }
                if (@fwrite($hTo, $data) === false) {
                    throw new UserMessageException(t('Failed to write decoded gzip data.'));
                }
            }
        } catch (Exception $x) {
            if (isset($hTo) && is_resource($hTo)) {
                @fclose($hTo);
            }
            if (isset($hFrom) && is_resource($hFrom)) {
                @gzclose($hFrom);
            }
            throw $x;
        }
        fclose($hTo);
        gzclose($hFrom);
    }
208256
public function rename($from, $to)
	{
		// If native FTP support is enabled let's use it...
		if (FTP_NATIVE)
		{
			if (@ftp_rename($this->conn, $from, $to) === false)
			{
				Log::add(__METHOD__ . 'Bad response.', Log::WARNING, 'jerror');

				return false;
			}

			return true;
		}

		// Send rename from command to the server
		if (!$this->_putCmd('RNFR ' . $from, 350))
		{
			Log::add(
				sprintf('%1$s: Bad response.  Server response: %2$s [Expected: 350].  From path sent: %3$s', __METHOD__, $this->response, $from),
				Log::WARNING, 'jerror'
			);

			return false;
		}

		// Send rename to command to the server
		if (!$this->_putCmd('RNTO ' . $to, 250))
		{
			Log::add(
				sprintf('%1$s: Bad response.  Server response: %2$s [Expected: 250].  To path sent: %3$s', __METHOD__, $this->response, $to),
				Log::WARNING, 'jerror'
			);

			return false;
		}

		return true;
	}
483696
public static void rename(String from, String to) {
        try {
            Files.move(Paths.get(from), Paths.get(to), StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            log.error("Error renaming file", e);
        }
    }
1049531
public function moveFolder( $from, $to )
	{
		$this->connection->checkConnection();
		if( ftp_size( $this->connection->getResource(), $from ) != -1 )
			throw new RuntimeException( 'Folder "'.$from.'" is not existing.' );
		return @ftp_rename( $this->connection->getResource(), $from, $to );
	}
436875
private function sendTokenEmail(UserInterface $user, $from, $to)
    {
        if (null === $user->getPasswordResetToken()) {
            throw new NoTokenFoundException($user);
        }

        $maxNumberEmails = $this->getParameter('sulu_security.reset_password.mail.token_send_limit');

        if ($user->getPasswordResetTokenEmailsSent() === $maxNumberEmails) {
            throw new TokenEmailsLimitReachedException($maxNumberEmails, $user);
        }
        $mailer = $this->get('mailer');
        $em = $this->getDoctrine()->getManager();
        $message = $mailer->createMessage()->setSubject(
                $this->getSubject()
            )->setFrom($from)->setTo($to)->setBody(
                $this->getMessage($user)
            );
        $mailer->send($message);
        $user->setPasswordResetTokenEmailsSent($user->getPasswordResetTokenEmailsSent() + 1);
        $em->persist($user);
        $em->flush();
    }
304650
private void rename(String from, String to) throws IOException
   {
      IndexOutputStream out = null;
      IndexInputStream in = null;
      try
      {
         out = new IndexOutputStream(dir.createOutput(to));
         in = new IndexInputStream(dir.openInput(from));
         DirectoryHelper.transfer(in, out);
      }
      finally
      {
         if (in != null)
         {
            in.close();
         }

         if (out != null)
         {
            out.flush();
            out.close();
         }
      }
      try
      {
         // delete old one
         if (dir.fileExists(from))
         {
            dir.deleteFile(from);
         }
      }
      catch (IOException e)
      {
         // do noting. Will be removed later
         if (LOG.isTraceEnabled())
         {
            LOG.trace("Can't deleted file: " + e.getMessage());
         }
      }
   }
612307
public function errorFileName($errorFileName = null)
    {
        if ($errorFileName === null)
        {
            return $this->_errorFileName;
        }
        $this->_errorFileName = $errorFileName;

        return $this;
    }
589049
public function cloneContentFile($file, $fromId, $toId) {
    // Determine source path
    if ($fromId === 'editor') {
      $sourcepath = $this->getEditorPath();
    }
    else {
      $sourcepath = "{$this->path}/content/{$fromId}";
    }
    $sourcepath .= '/' . $file;

    // Determine target path
    $filename = basename($file);
    $filedir = str_replace($filename, '', $file);
    $targetpath = "{$this->path}/content/{$toId}/{$filedir}";

    // Make sure it's ready
    self::dirReady($targetpath);

    $targetpath .= $filename;

    // Check to see if source exist and if target doesn't
    if (!file_exists($sourcepath) || file_exists($targetpath)) {
      return; // Nothing to copy from or target already exists
    }

    copy($sourcepath, $targetpath);
  }
957493
final protected function publishDirectory($from, $to)
    {
        // Load mount manager
        $manager = new MountManager([
            'from' => new Flysystem(new LocalAdapter($from)),
            'to'   => new Flysystem(new LocalAdapter($to)),
        ]);

        // Copy directory to application
        foreach ($manager->listContents('from://', true) as $file) {
            if ($file['type'] !== 'file') {
                continue;
            }
            $manager->put(sprintf('to://%s', $file['path']), $manager->read(sprintf('from://%s', $file['path'])));
        }

        // Output status message
        $this->getCommand()->line(
            sprintf('<info>Copied %s</info> <comment>[%s]</comment> <info>To</info> <comment>[%s]</comment>',
                'Directory', str_replace(base_path(), '', realpath($from)), str_replace(base_path(), '', realpath($to)))
        );
    }
496466
public function replaceMessageUser(User $from, User $to)
    {
        $messages = $this->messageRepo->findByCreator($from);
        if (count($messages) > 0) {
            foreach ($messages as $message) {
                $message->setCreator($to);
                $message->setAuthor($to->getFirstName().' '.$to->getLastName());
            }
            $this->om->flush();
        }

        return count($messages);
    }
570826
public static function sendGreenAlert(string $text, int $to_user_id = USER_ID, int $from_user_id = 0): UsersMessageEntity
    {
        return self::sendMessage($text, $to_user_id, $from_user_id, self::TOASTR_MESSAGE_COLOR_GREEN);
    }
335024
public function compile( string$fromFile, string$toFile='' )
	{
		$fromFile= $this->getFilePath($fromFile);

		$result= $this->execute(new FileBuffer($this,$fromFile));

		if( $toFile ){
			return file_put_contents($toFile,$result);
		}else{
			return $result;
		}
	}
1256931
public function mailFrom($fromUser,$fromDomain) {
        if (!($this->transport->getSmtp()->mail($fromUser. '@' . $fromDomain))) {

            // MAIL FROM not accepted, we can't talk
            $this->statusManager->setStatus($this->users, $this->dom, $this->options['noCommIsValid'],'MAIL FROM not accepted');
        }
    }
1374526
private function writeSession($message, $from = '', $is_error = false){
        if( session_id() ){
            $key = $is_error ? $this->error_key : $this->message_key;
            // Initialize
            if( !isset($_SESSION[$key]) || !is_array($_SESSION[$key]) ){
                $_SESSION[$key] = [];
            }
            // Add message
            $_SESSION[$key][] = ( empty($from) ? '' : sprintf('<strong>[%s]</strong> ', $from) ).$message;
        }
    }
532358
public function rename($from, $to) {
    if (!CloudStorageTools::parseFilename($from, $from_bucket, $from_object) ||
        !isset($from_object)) {
      trigger_error(sprintf("Invalid Google Cloud Storage path: %s", $from),
                    E_USER_ERROR);
      return false;
    }
    if (!CloudStorageTools::parseFilename($to, $to_bucket, $to_object) ||
        !isset($to_object)) {
      trigger_error(sprintf("Invalid Google Cloud Storage path: %s", $to),
                    E_USER_ERROR);
      return false;
    }

    // If the file being renamed is an uploaded file being moved to an allowed
    // include bucket trigger a warning.
    $allowed_buckets = $this->getAllowedBuckets();
    foreach ($_FILES as $file) {
      if ($file['tmp_name'] == $from) {
        foreach ($allowed_buckets as $allowed_bucket) {
          // 5th character indicates start of bucket since it ignores 'gs://'.
          if (strpos($to, $allowed_bucket) === 5) {
            trigger_error(sprintf('Moving uploaded file (%s) to an allowed ' .
                                  'include bucket (%s) which may be ' .
                                  'vulnerable to local file inclusion (LFI).',
                                  $from, $allowed_bucket),
                          E_USER_WARNING);
            break 2;
          }
        }
      }
    }

    $client = new CloudStorageRenameClient($from_bucket,
                                           $from_object,
                                           $to_bucket,
                                           $to_object,
                                           $this->context);
    return $client->rename();
  }
1176359
protected function buildReply($to, $from, $message)
    {
        $base = [
            'ToUserName'   => $to,
            'FromUserName' => $from,
            'CreateTime'   => time(),
            'MsgType'      => is_array($message) ? current($message)->getType() : $message->getType(),
        ];

        $transformer = new Transformer();

        return XML::build(array_merge($base, $transformer->transform($message)));
    }
482073
public static void copyFile(File from, File to) throws RuntimeIOException {
		copyFile(from, to, false);
	}