[ Index ] |
PHP Cross Reference of phpSSH |
[Source view] [Print]
ssh.php -- a class to execute remote commands over SSH This file contains the files-based implementation of the SExec class. This implementation relies on the usage of regular temporary files to communicate with the remote end, thus avoiding several drawbacks (mainly deadlocks) associated with pipes.
Author: | José R. Valverde |
File Size: | 1309 lines (48 kb) |
Included or required: | 2 times |
Referenced: | 0 times |
Includes or requires: | 1 file ssh.php |
sexec:: (13 methods):
sexec()
destruct()
ssh_copy()
ssh_copy_to()
ssh_copy_from()
ssh_passthru()
ssh_exec()
ssh_open_shell()
ssh_open_command()
ssh_out_expect()
ssh_close()
ssh_popen()
ssh_pclose()
sexec($remote="localhost", $password="xxyzzy") X-Ref |
No description |
destruct() X-Ref |
No description |
ssh_copy($origin, $destination, $password) X-Ref |
Copy a file or directory from one source to a destination This function copies source to dest, where one of them is a local filespec and the other a remote filespec of the form [user@]host:path If the original source is a directory, it will be copied recursively to destination (hence easing file transfers). The function returns TRUE on success or FALSE on failure. <b>EFFICIENCY NOTICE:</b> The copy routines use 'scp' to do their actual work. Since scp seems to be unable to hitchhike on the master channel, we must do authentication for each copy operation (subroutine call). These routines are hence a lot more time-expensive than all the other ones. You may want to consider whether you can group several copies into one single call to reduce authentication overheads. |
ssh_copy_to($localpath, $remotepath, &$out) X-Ref |
Copy a file or directory from a local source to a remote destination This function copies source to dest, where first of them is a local filespec and then comes a remote filespec as a normal system path. Both, local and remote paths may be absolute or relative. If the original source is a directory, it will be copied recursively to destination (hence easing file transfers). The function returns TRUE on success or FALSE on failure. |
ssh_copy_from($remotepath, $localpath, &$out) X-Ref |
Copy a file or directory from a remote source to a local destination This function copies source to dest, where first of them is a remote filespec and then comes a local filespec, both specified as normal system paths. Both, local and remote paths may be absolute or relative. If the original source is a directory, it will be copied recursively to destination (hence easing file transfers). The function returns TRUE on success or FALSE on failure. |
ssh_passthru($command, &$status) X-Ref |
Execute a single command remotely Execute a single command remotely using ssh and display its output, optionally returning its exit status (like passthru) This function is intended to be used as a one-time all-at-once non-interactive execution mechanism which will run the command remotely and display its output. If you try to issue an interactive command using this function, all you will get is unneccessary trouble. So don't! This might be done as well using a pipe on /tmp and making the command 'cat' the pipe: when ssh runs, it runs the command 'cat' on the pipe and hangs on read. Then we just need a thread to open the pipe, put the password and close the pipe. This other way the password is never wirtten down. But, OTOH, the file life is so ephemeral that most of the time it will only exist in the internal system cache, so this approach is not that bad either. |
ssh_exec($command, &$out) X-Ref |
Execute a remote command using SSH This function sort of mimics rexec(3) using SSH as the transport protocol. The function returns the exit status of the remote command, and appends the remote job output to an optional argument. This function is intended to be used as a one-time all-at-once non-interactive execution mechanism which will run the command remotely and return its output. If you try to issue an interactive command using this function, all you will get is unneccessary trouble. So don't! |
ssh_open_shell() X-Ref |
Open an SSH connection to a remote site with a shell to run interactive commands Connects to a remote host and opens an interactive shell session with NO controlling terminal. This routine creates communication streams with the remote shell, and stores all output (standard and error) of the connection into two separate local log files (one for stdout and one for stderr). Returns a process_control array which contains the process resource ID and an the standard file descriptors which the caller may use to interact with the remote shell. The process control array contains: 'process' -- the process resource for the newly created connection 'std_in' -- handle to the standard input of the new connection 'std_out' -- handle to standard output of the new connection 'std_err' -- handle to standard error of the new connection 'stdout_file' -- actual filename of the local log file for the new connection standard output 'stderr_file' -- actual filename of the local log file for the new connection standard error |
ssh_open_command($command) X-Ref |
Open an SSH connection to run an interactive command on a remote site Connects to a remote host and runs an interactive command with NO controlling terminal. This routine creates communication streams with the remote shell, and stores all output (standard and error) of the connection into two separate local log files (one for stdout and one for stderr). Returns a process_control array which contains the process resource ID and an the standard file descriptors which the caller may use to interact with the remote shell. The process control array contains: 'process' -- the process resource for the newly created connection 'std_in' -- handle to the standard input of the new connection 'std_out' -- handle to standard output of the new connection 'std_err' -- handle to standard error of the new connection 'stdout_file' -- actual filename of the local log file for the new connection standard output 'stderr_file' -- actual filename of the local log file for the new connection standard error |
ssh_out_expect($p, $expr="^# ") X-Ref |
Get output until we reach a given regular expression |
ssh_close($p) X-Ref |
Close an SSH interactive session This method terminates a previously open interactive remote session. It will send a termination notification to the remote end, close the connection with control and communication streams, and terminate the local control process. Copies of the log files that contain the output and error of the communication are left out for later reference and local peruse. If you don't need them any longer, you may delete them or just leave them around until the class destructor is called (which will remove all session traces), |
ssh_popen($command, $mode) X-Ref |
Execute a remote command and keep an unidirectional stream contact with it. This routine mimics 'popen()' but uses ssh to connect to a remote host and run the requested command: in other words, it opens a pipe to a remotely executed command. This pipe is unidirectional, with the communications direction controlled by a method parameter. |
ssh_pclose($f) X-Ref |
Close a piped remote execution command control pipe. This routine accepts as input the handle for the control stream of a remote command and closes it, terminating the command as well. The handle must be valid and obtained through a call to ssh_popen(). |
Generated: Tue May 31 15:44:47 2005 | Cross-referenced by PHPXref 0.4.1 |