Telnet DO negotiaion

@param    char   $cmd    Binary representation of command char

@throws   SocketClientException   On socket communication error
@return   int                     Bytes written
359145
private function _negotiateDo($cmd) {
        switch ($cmd) {
            case TEL_TTYPE: // Send terminal type
                $term = (binary) $this->terminal_type;
                return $this->send(TEL_IAC.TEL_SUB.TEL_TTYPE.TEL_BIN.$term.
                            TEL_IAC.TEL_SUBEND,false);
            case TEL_XDISPLOC: // Send display location
                $hostname = (binary) php_uname('n').':0.0';
                return $this->send(TEL_IAC.TEL_SUB.TEL_XDISPLOC.TEL_BIN.$hostname.
                            TEL_IAC.TEL_SUBEND, false);
            case TEL_NEWENV: // Send new environment name
                $env = (binary) 'DISPLAY ' . php_uname('n'). ':0.0';
                return $this->send(TEL_IAC.TEL_SUB.TEL_NEWENV.TEL_BIN.$env.
                            TEL_IAC.TEL_SUBEND, false);
            case TEL_TSPEED: // Send terminal speed
                $tspeed = (binary) $this->terminal_speed_in . ','. $this->terminal_speed_out;
                return $this->send(TEL_IAC.TEL_SUB.TEL_TSPEED.TEL_BIN.$tspeed.
                            TEL_IAC.TEL_SUBEND, false);
            case TEL_NAWS: // Negotiate about window size
                $null = chr(0);
                $height = chr($this->window_size_height);
                $width = chr($this->window_size_width);
                return $this->send(TEL_IAC.TEL_SUB.TEL_NAWS.$null.$width.$null.$height.
                    TEL_IAC.TEL_SUBEND, false);
            case TEL_GA:
                break;
            case TEL_ECHO: // This is workaround for some strange thing
                return $this->send(TEL_IAC.TEL_WONT.TEL_ECHO, false);
            default: // In case we didn't implement - tell that we will don't
                     // use this option
                return $this->send(TEL_IAC.TEL_DONT.$cmd, false);
        }
    }
249590
public static function ord(string $char): int
    {
        $h = \ord($char[0]);
        
        if ($h <= 0x7F) {
            return $h;
        }
        
        if ($h < 0xC2) {
            throw new \InvalidArgumentException('Could not get unicode codepoint for character: "' . $char . '"');
        }
        
        if ($h <= 0xDF) {
            return ($h & 0x1F) << 6 | (\ord($char[1]) & 0x3F);
        }
        
        if ($h <= 0xEF) {
            return (($h & 0x0F) << 12 | (\ord($char[1]) & 0x3F) << 6 | (\ord($char[2]) & 0x3F));
        }
        
        if ($h <= 0xF4) {
            return (($h & 0x0F) << 18 | (\ord($char[1]) & 0x3F) << 12 | (\ord($char[2]) & 0x3F) << 6 | (\ord($char[3]) & 0x3F));
        }
        
        throw new \InvalidArgumentException('Could not get unicode codepoint for character: "' . $char . '"');
    }
625840
function write($cmd)
    {
        if (!($this->bitmap & NET_SSH2_MASK_LOGIN)) {
            user_error('Operation disallowed prior to login()', E_USER_NOTICE);
            return false;
        }

        if (!($this->bitmap & NET_SSH2_MASK_SHELL) && !$this->_initShell()) {
            user_error('Unable to initiate an interactive shell session', E_USER_NOTICE);
            return false;
        }

        return $this->_send_channel_packet(NET_SSH2_CHANNEL_SHELL, $cmd);
    }
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;
    }
1148200
private function execCmd($cmd, &$stdout = null, &$stderr = null)
    {
        $descriptorspec = array(
            0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
            1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
            2 => array("pipe", "w")   // stderr is a file to write to
        );

        $pipes= array();
        $process = proc_open($cmd, $descriptorspec, $pipes);

        $stdout = "";
        $stderr = "";

        if (!is_resource($process)) {
            return false;
        }

        #close child's input imidiately
        fclose($pipes[0]);

        stream_set_blocking($pipes[1], false);
        stream_set_blocking($pipes[2], false);

        $todo= array($pipes[1],$pipes[2]);

        while (true) {
            $readstdout = [];
            $readstderr = [];

            if (false !== !feof($pipes[1])) {
                $readstdout[]= $pipes[1];
            }

            if (false !== !feof($pipes[2])) {
                $readstderr[]= $pipes[2];
            }

            if (empty($readstdout)) {
                break;
            }

            $write = null;
            $ex = null;
            $ready = stream_select($readstdout, $write, $ex, 2);

            if (false === $ready) {
                // probably dead process
                break;
            }

            foreach ($readstdout as $out) {
                $line = fread($out, 1024);
                $stdout.= $line;
            }

            foreach ($readstderr as $out) {
                $line = fread($out, 1024);
                $stderr.= $line;
            }
        }

        $stdout = strlen($stdout) > 0 ? $stdout : null;
        $stderr = strlen($stderr) > 0 ? $stderr : null;

        fclose($pipes[1]);
        fclose($pipes[2]);

        return proc_close($process);
    }
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");
            }
        }
    }
1244780
protected function execCommand(string $cmd, ...$args)
    {
        $command = $this->predis->createCommand($cmd, $args);
        $response = $this->predis->executeCommand($command);

        if ($response instanceof ErrorInterface) {
            return false;
        }

        if ($response instanceof Status) {
            return $response->getPayload() === 'OK';
        }

        return $response;
    }
316778
function write($cmd)
    {
        if (!$this->isAuthenticated()) {
            user_error('Operation disallowed prior to login()');
            return false;
        }

        if (!($this->bitmap & self::MASK_SHELL) && !$this->_initShell()) {
            user_error('Unable to initiate an interactive shell session');
            return false;
        }

        return $this->_send_channel_packet($this->_get_interactive_channel(), $cmd);
    }
1108940
protected function unknownCommand(string $command): int
	{
		$message = 'Unknown command [ ' . $command . ' ].';

		if(($suggestion = $this->suggest($command, array_keys($this->commands))) !== null)
		{
			$message .= ' Did you mean [ ' . $suggestion . ' ]?';
		}

		$this->output->writeLn('<red>' . $message . '</red>');

		$this->listCommands();

		return CommandInterface::STATUS_ERROR;
	}
128752
function cmd_PORT($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $port = explode(",", $cmd[1]);
        if (count($port) != 6)
        {
            $this->send($fd, "501 Syntax error in IP address");
        }
        else
        {
            if (!$this->isIPAddress($port))
            {
                $this->send($fd, "501 Syntax error in IP address");
                return;
            }
            $ip = $port[0] . "." . $port[1] . "." . $port[2] . "." . $port[3];
            $port = hexdec(dechex($port[4]) . dechex($port[5]));
            if ($port < 1024)
            {
                $this->send($fd, "501 Sorry, but I won't connect to ports < 1024");
            }
            elseif ($port > 65000)
            {
                $this->send($fd, "501 Sorry, but I won't connect to ports > 65000");
            }
            else
            {
                $ftpsock = fsockopen($ip, $port);
                if ($ftpsock)
                {
                    $this->users[$user]['sock'] = $ftpsock;
                    $this->users[$user]['pasv'] = false;
                    $this->send($fd, "200 PORT command successful");
                }
                else
                {
                    $this->send($fd, "501 Connection failed");
                }
            }
        }
    }
475278
final public static function exec(string $cmd, array $args=[]) {
		foreach ($args as $key => $val)
			$args[$key] = escapeshellarg($val);
		$cmd = vsprintf($cmd, $args);
		exec($cmd, $output, $retcode);
		if ($retcode !== 0)
			return false;
		return $output;
	}
264125
def _send_cmd(self, cmd: str):
        """"""
        self._sock.sendall(cmd.encode(encoding='latin-1', errors='strict'))
184027
public function command($cmd, $q = '', $cb = null)
    {
        if ($this->phase !== self::PHASE_HANDSHAKED) {
            return false;
        }

        $this->onResponse->push($cb);
        $this->seq = 0;
        $this->sendPacket(chr($cmd) . $q);

        return true;
    }
308496
protected function write($command)
    {
        try {
            $this->socket->write($command . $this->lineEnding);
        } catch (Exception $e) {
            throw new TelnetException(sprintf('failed writing to socket [%s]', $command), 0, $e);
        }
    }
856536
public function writeLine(string $bytes): int
    {
        return $this->outputStream->writeLine(iconv('UTF-8', $this->charset, $bytes));
    }
49836
function cmd_RETR($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $ftpsock = $this->getUserSock($user);
        if (($file = $this->getFile($user, $cmd[1])) != false)
        {
            $this->send($fd, "150 Connecting to client");
            if ($fp = fopen($file, "r"))
            {
                while (!feof($fp))
                {
                    $cont = fread($fp, 1024);
                    if (!fwrite($ftpsock, $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");
                }
            }
            else
            {
                $this->send($fd, "550 Can't open " . $cmd[1] . ": Permission denied");
            }
        }
        else
        {
            $this->send($fd, "550 Can't open " . $cmd[1] . ": No such file or directory");
        }
    }
422452
public static StringBuffer runCommand(String[] cmd) {
    StringBuffer retval = new StringBuffer(MAX_OUTPUT_LENGTH);
    Process p;
    try {
      p = Runtime.getRuntime().exec(cmd);
      InputStream tmp = p.getInputStream();
      p.waitFor();
      int c;
      while ((c = tmp.read()) != -1)
        retval.append((char) c);
    } catch (IOException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    return retval;
  }