文件重命名,源文件
@param $fd
@param $cmd
178881
function cmd_RNFR($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $file = $this->fillDirName($user, $cmd[1]);
        if (!file_exists($file))
        {
            $this->send($fd, "550 Sorry, but that file doesn't exist");
        }
        else
        {
            $this->users[$user]['rename'] = $file;
            $this->send($fd, "350 RNFR accepted - file exists, ready for destination");
        }
    }
64177
public static function checkCmd($cmd)
    {
        // cut out the actual executable part only
        // and leave args away
        $cmdParts = preg_split("/\s+/", $cmd);
        $cmd = $cmdParts[0];

        // try to find a command if not absolute path is given
        if (!preg_match('/^\.?\/.*$/', $cmd)) {
            $retval = null;
            $ouput = [];
            $fullCmd = exec("which $cmd", $output, $retval);
            if ($retval) {
                throw new InvalidArgumentException(sprintf("Failed to find full path for '%s'", $cmd));
            }
            $cmd = trim($fullCmd);
        }

        if (!file_exists($cmd)) {
            throw new InvalidArgumentException(sprintf("'%s' does not exist", $cmd));
        }

        if (!is_file($cmd)) {
            throw new InvalidArgumentException(sprintf("'%s' is not a file", $cmd));
        }
        if (!is_executable($cmd)) {
            throw new InvalidArgumentException(sprintf("'%s' is not executable", $cmd));
        }

        return true;
    }
548507
public function executeCommand($cmd)
    {
        $this->checkConnected();

        $write = @fwrite($this->socket, "$cmd\r\n");
        if (false === $write) {
            throw new Exception\IOError('Error while writing to the Tor server');
        }

        $data = [];
        while (true) {
            $response = fread($this->socket, 1024);

            $multiline = false;
            $last_code = null;
            $last_separator = null;
            foreach (explode("\r\n", $response) as $line) {
                $code = substr($line, 0, 3);
                $separator = substr($line, 3, 1);
                $message = substr($line, 4);

                if ('+' === $separator) {
                    $multiline = true;
                    $last_code = $code;
                    $last_separator = $separator;
                }

                if ($multiline) {
                    $data[] = [
                        'code' => $last_code,
                        'separator' => $last_separator,
                        'message' => $line,
                    ];
                } else {
                    if (false === $code || false === $separator) {
                        $e = new Exception\ProtocolError('Bad response format');
                        $e->setResponse($response);

                        throw $e;
                    }

                    if (!in_array($separator, [' ', '+', '-'])) {
                        $e = new Exception\ProtocolError('Unknown separator');
                        $e->setResponse($response);

                        throw $e;
                    }

                    if (!in_array(substr($code, 0, 1), ['2', '6'])) {
                        $e = new Exception\TorError($message, $code);
                        $e->setResponse($response);

                        return $e;
                    }

                    $data[] = [
                        'code' => $code,
                        'separator' => $separator,
                        'message' => $message,
                    ];
                }

                if (' ' === $separator) {
                    break 2;
                }
            }
        }

        return $data;
    }
482891
public function commandExists($cmd) {
		return $this->loaded && isset($this->commands[$cmd]) && method_exists($this, $cmd);
	}
879683
public function background_proc( $cmd ) {
		$descriptors = array(
			0 => STDIN,
			1 => array( 'pipe', 'w' ),
			2 => array( 'pipe', 'w' ),
		);

		$proc = proc_open( $cmd, $descriptors, $pipes, $this->variables['RUN_DIR'], self::get_process_env_variables() );

		sleep(1);

		$status = proc_get_status( $proc );

		if ( !$status['running'] ) {
			$stderr = is_resource( $pipes[2] ) ? ( ': ' . stream_get_contents( $pipes[2] ) ) : '';
			throw new RuntimeException( sprintf( "Failed to start background process '%s'%s.", $cmd, $stderr ) );
		} else {
			$this->running_procs[] = $proc;
		}
	}
143811
public function cmd($cmd)
    {
        $cmd = ltrim($cmd);
        if (substr($cmd, 0, 1) === '@') {
            return $this->resolve(array_merge(array('tasks'), explode('.', substr($cmd, 1))));
        } else {
            $this->exec($cmd);
            return null;
        }
    }
1288891
protected function removeJobFromExecFile($cmd)
    {
        $jobs = $this->listArray();

        unset($jobs[$cmd]);

        file_put_contents($this->crontabCommands, implode(EOL, $jobs) . EOL);
    }
1260065
protected function addJobToExecFile($cmd)
    {
        $content = file_get_contents($this->crontabCommands);

        if( ! stristr($content, $cmd))
        {
            $content = $content . $this->getValidCommand() . $cmd . EOL;

            file_put_contents($this->crontabCommands, $content);
        }
    }
373328
public function exec($cmd)
    {
        
        if ($this->jumphost) {
            $cmd = "ssh " . $this->jumphost . " " . $cmd;
        }
        
        if ( ! ($stream = ssh2_exec($this->connection, $cmd))) {
            throw new \Exception('SSH command failed');
        }
        stream_set_blocking($stream, true);
        $data = "";
        while ($buf = fread($stream, 4096)) {
            $data .= $buf;
        }
        fclose($stream);
        
        return $data;
    }
524039
protected function instantiateSingleCommand($cmd)
    {
        $command = null;

        if (!is_array($cmd)) {
            $cmd = ['cmd' => $cmd];
        }

        if (!isset($cmd['cmd'])) {
            $cmd['cmd'] = null;
        }

        if (isset($cmd['cmd'])) {
            $cmd['cmd'] = trim($cmd['cmd']);
            if (0 < preg_match('/^\?([^\:]+)\:(.+)$/', $cmd['cmd'], $matches)) {
                $cmd['if'] = trim($matches[1]);
                $cmd['cmd'] = trim($matches[2]);
            }
            if ('!' === substr($cmd['cmd'], 0, 1)) {
                $cmd['command'] = trim(substr($cmd['cmd'], 1));
            } elseif ('@' === substr($cmd['cmd'], 0, 1)) {
                list ($cmdName) = explode(' ', trim(substr($cmd['cmd'], 1)), 2);
                if (is_file('bin/dev-'.$cmdName)) {
                    $cmd['command'] = sprintf('bin/dev-%s', trim(substr($cmd['cmd'], 1)));
                } else {
                    $cmd['command'] = sprintf('bin/dev %s', trim(substr($cmd['cmd'], 1)));
                }
            } elseif ('#' === substr($cmd['cmd'], 0, 1)) {
                $cmd['class'] = Command\ShellScriptCommand::class;
                $scriptName = trim(substr($cmd['cmd'], 1));
                $description = null;
                if (false !== strpos($scriptName, ',')) {
                    list($scriptName, $description) = explode(',', $scriptName, 2);
                }
                $cmd['args'] = [$scriptName];
                $cmd['description'] = $description;
            } else {
                $cmd['class'] = trim($cmd['cmd']);
            }
            unset($cmd['cmd']);
        }

        if (isset($cmd['command'])) {
            $command = new Command\ExecCommand($cmd['command']);
        } elseif (isset($cmd['class'])) {
            if (!class_exists($cmd['class'])) {
                throw new \RuntimeException(sprintf("Unknown class '%s'", $cmd['class']), 51);
            }
            $r       = new \ReflectionClass($cmd['class']);
            $command = $r->newInstanceArgs((isset($cmd['args']) && is_array($cmd['args'])) ? $cmd['args'] : []);
        }

        if (!is_object($command)) {
            throw new \RuntimeException(sprintf("Unable to instantiate command '%s'", json_encode($cmd)), 50);
        }

        if (isset($cmd['description'])) {
            $command->setDescription($cmd['description']);
        }

        if (isset($cmd['if'])) {
            $command = new Command\ConditionedCommand($command, trim($cmd['if']), $this->getExpressionService());
        }

        return $command;
    }
241157
private function createHeader($cmd, $bytes)
    {
        $retval = chr($cmd);

        $bytes_left = $bytes;
        do {
            $byte = $bytes_left % 128;
            $bytes_left >>= 7;

            if($bytes_left>0) {
              $byte = $byte | 0x80;
            }

            $retval.=chr($byte);

        } while($bytes_left>0);

        return $retval;
    }
904310
function cmd_STOR($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $ftpsock = $this->getUserSock($user);
        $file = $this->fillDirName($user, $cmd[1]);
        $this->debug("PUT: $file");
        $fp = fopen($file, "w");
        if (!$fp)
        {
            $this->send($fd, "553 Can't open that file: Permission denied");
        }
        else
        {
            $this->send($fd, "150 Connecting to client");
            while (!feof($ftpsock))
            {
                $cont = fread($ftpsock, 8192);
                if (!$cont) break;
                if (!fwrite($fp, $cont)) break;
            }
            if (fclose($fp) and $this->closeUserSock($user))
            {
                $this->send($fd, "226 File successfully transferred");
            }
            else
            {
                $this->send($fd, "550 Error during file-transfer");
            }
        }
    }
31807
public static function detectCmdLocationInPaths($cmd, array $paths) : string
    {
        foreach ($paths as $path) {
            $command = $path . DIRECTORY_SEPARATOR . $cmd;
            $bin     = self::getExecutable($command);
            if (null !== $bin) {
                return $bin;
            }
        }
        return '';
    }
489369
protected function getCommand($cmd, $tokens)
    {
        return Template::parse($cmd, $tokens, '%%', '%%', Template::FLAG_RECURSIVE | Template::FLAG_EMPTY_MISSING);
    }
104686
private function exec($cmd, $input = '')
    {
        // Cannot use $_SERVER superglobal since that's empty during UnitUnishTestCase
        // getenv('HOME') isn't set on Windows and generates a Notice.
        if ($this->prefixExecWithExportHome) {
          $home = getenv('HOME');
          if (!is_writable($home)) {
              $cmd = 'export HOME=/tmp && ' . $cmd;
          }
        }
        $process = proc_open($cmd, [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
        fwrite($pipes[0], $input);
        fclose($pipes[0]);
        $stdout = stream_get_contents($pipes[1]);
        fclose($pipes[1]);
        $stderr = stream_get_contents($pipes[2]);
        fclose($pipes[2]);
        $rtn = proc_close($process);

        return [
            'stdout' => $stdout,
            'stderr' => $stderr,
            'return' => $rtn
        ];
    }
221682
function cmd_RNTO($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $old_file = $this->users[$user]['rename'];
        $new_file = $this->fillDirName($user, $cmd[1]);
        $this->debug("RENAME: $old_file to $new_file");
        if (empty($old_file) or !is_dir(dirname($new_file)))
        {
            $this->send($fd, "451 Rename/move failure: No such file or directory");
        }
        elseif (rename($old_file, $new_file))
        {
            $this->send($fd, "250 File successfully renamed or moved");
        }
        else
        {
            $this->send($fd, "451 Rename/move failure: Operation not permitted");
        }
        unset($this->users[$user]['rename']);
    }
114324
public function spawn($cmd, $options = array(), $start = true)
    {
        // Generate guid
        $guid = uniqid();
        // Get create directory
        $dir = !empty($options['dir']) ? $options['dir'] : sys_get_temp_dir();
        // Events name
        $types = array('stdin', 'stdout', 'stderr');
        // Files to descriptor
        $files = array();
        // Self
        $self = $this;

        // Define the stdin stdout and stderr files
        foreach ($types as $type) {
            $files[] = $file = $dir . '/' . $guid . '.' . $type;
            posix_mkfifo($file, 0600);
        }

        $child = $this->parallel(function ($process) use ($cmd, $files) {
            $pipes = array();

            // Make file descriptors for proc_open()
            $fd = array();
            foreach ($files as $i => $file) {
                $fd[] = array('file', $file, $i > 0 ? 'w' : 'r');
            }

            // Open pipe to run process
            $resource = proc_open($cmd, $fd, $pipes);

            if (!is_resource($resource)) {
                throw new \RuntimeException('Can not run "' . $cmd . '" using pipe open');
            }

            // Close all pipes
            foreach ($pipes as $pipe) {
                fclose($pipe);
            }

            proc_close($resource);
            exit;
        }, $options, $start);

        $child->on('fork', function () use (&$files, $child, $types, $self) {
            // Make file descriptor
            $pipes = array();
            foreach ($files as $i => $file) {
                $pipes[] = fopen($file, $i > 0 ? 'r' : 'w');
            }

            // Create tick process callback
            $tick = function () use ($pipes, $child, $types) {
                $readers = $pipes;

                // Select the streams
                if (empty($readers) || stream_select($readers, $null, $null, 0) <= 0) return;

                // Check which reader selected and emit event
                foreach ($readers as $reader) {
                    if (!is_resource($reader)) continue;
                    $index = array_search($reader, $pipes);
                    while (!feof($reader)) {
                        $child->emit($types[$index], fgets($reader));
                    }
                }
            };

            // Register tick function to check streams
            $self->on('tick', $tick);

            // Remove file when exit
            $child->on('exit', function () use ($tick, $self, &$files, &$pipes) {
                $self->removeListener('tick', $tick);
                foreach ($files as $file) {
                    unlink($file);
                }
                $files = $pipes = array();
            });
        });

        return $child;
    }