113 if ($ssh instanceof
SSH2) {
114 $this->mode = self::MODE_SSH2;
115 } elseif ($ssh instanceof
SSH1) {
116 $this->packet_size = 50000;
117 $this->mode = self::MODE_SSH1;
146 function put($remote_file,
$data, $mode = self::SOURCE_STRING, $callback = null)
148 if (!isset($this->ssh)) {
152 if (!$this->ssh->exec(
'scp -t ' . escapeshellarg($remote_file),
false)) {
157 if ($temp !== chr(0)) {
161 if ($this->mode == self::MODE_SSH2) {
162 $this->packet_size = $this->ssh->packet_size_client_to_server[
SSH2::CHANNEL_EXEC] - 4;
165 $remote_file = basename($remote_file);
167 if ($mode == self::SOURCE_STRING) {
170 if (!is_file(
$data)) {
171 user_error(
"$data is not a valid file", E_USER_NOTICE);
182 $this->
_send(
'C0644 ' .
$size .
' ' . $remote_file .
"\n");
185 if ($temp !== chr(0)) {
190 while ($sent <
$size) {
191 $temp = $mode & self::SOURCE_STRING ? substr(
$data, $sent, $this->packet_size) : fread($fp, $this->packet_size);
193 $sent+= strlen($temp);
195 if (is_callable($callback)) {
196 call_user_func($callback, $sent);
201 if ($mode != self::SOURCE_STRING) {
220 function get($remote_file, $local_file =
false)
222 if (!isset($this->ssh)) {
226 if (!$this->ssh->exec(
'scp -f ' . escapeshellarg($remote_file),
false)) {
232 if (!preg_match(
'#(?<perms>[^ ]+) (?<size>\d+) (?<name>.+)#', rtrim($this->
_receive()),
$info)) {
240 if ($local_file !==
false) {
241 $fp = @
fopen($local_file,
'wb');
253 if ($local_file ===
false) {
262 if ($local_file !==
false) {
278 switch ($this->mode) {
279 case self::MODE_SSH2:
282 case self::MODE_SSH1:
284 $this->ssh->_send_binary_packet(
$data);
296 switch ($this->mode) {
297 case self::MODE_SSH2:
299 case self::MODE_SSH1:
300 if (!$this->ssh->bitmap) {
304 $response = $this->ssh->_get_binary_packet();
306 case NET_SSH1_SMSG_STDOUT_DATA:
308 return $this->ssh->_string_shift(
$response[SSH1::RESPONSE_DATA], $length);
309 case NET_SSH1_SMSG_STDERR_DATA:
311 case NET_SSH1_SMSG_EXITSTATUS:
312 $this->ssh->_send_binary_packet(chr(NET_SSH1_CMSG_EXIT_CONFIRMATION));
313 fclose($this->ssh->fsock);
314 $this->ssh->bitmap = 0;
317 user_error(
'Unknown packet received', E_USER_NOTICE);
331 switch ($this->mode) {
332 case self::MODE_SSH2:
335 case self::MODE_SSH1:
336 $this->ssh->disconnect();
const SOURCE_STRING
Reads data from a string.
Pure-PHP implementations of SCP.
Pure-PHP implementation of SSHv1.
_send($data)
Sends a packet to an SSH server.
Pure-PHP implementation of SSHv2.
_close()
Closes the connection to an SSH server.
__construct($ssh)
Default Constructor.
const SOURCE_LOCAL_FILE
#+ public
put($remote_file, $data, $mode=self::SOURCE_STRING, $callback=null)
Uploads a file to the SCP server.
_receive()
Receives a packet from an SSH server.
const RESPONSE_DATA
The Response Data.
const MODE_SSH2
SSH2 is being used.