116 $this->packet_size = 50000;
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);
175 $fp = @fopen(
$data,
'rb');
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) {
284 $this->ssh->_send_binary_packet(
$data);
296 switch ($this->mode) {
300 if (!$this->ssh->bitmap) {
304 $response = $this->ssh->_get_binary_packet();
306 case NET_SSH1_SMSG_STDOUT_DATA:
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) {
336 $this->ssh->disconnect();
An exception for terminatinating execution or to throw for unit testing.
const SOURCE_LOCAL_FILE
#+ @access public
_receive()
Receives a packet from an SSH server.
__construct($ssh)
Default Constructor.
_close()
Closes the connection to an SSH server.
_send($data)
Sends a packet to an SSH server.
const MODE_SSH2
SSH2 is being used.
const SOURCE_STRING
Reads data from a string.
put($remote_file, $data, $mode=self::SOURCE_STRING, $callback=null)
Uploads a file to the SCP server.
const RESPONSE_DATA
The Response Data.
Pure-PHP implementations of SCP.
Pure-PHP implementation of SSHv1.
Pure-PHP implementation of SSHv2.