Pushy provides various builtin transports, which are defined here. Each transport module provides a pushy.transport.Popen() function for creating a transport object, whose class inherits from pushy.transport.BaseTransport.
Executes command, returning an object representing the process, with pipes for standard I/O.
Each transport module must define this function, which will be used to return an object specific to that transport. For example, the local module provides a Popen function which simply wraps subprocess.Popen(). Each transport may expect different keyword parameters.
The base class for all transports.
The address to which this transport connection was made.
The standard input file object for the process created by this transport.
The standard output file object for the process created by this transport.
The standard error file object for the process created by this transport.
Note
Some transports may not provide access to standard error, in which case they must provide a file like object which simply returns nothing when read from. Pushy only reads from stderr when an error has occurred. The absence of a real stderr file will not stop Pushy from working, but it will mean that diagnosing problems with Pushy will be more difficult.
If defined by a transport, this method is used by pushy.PushyClient.getfile() for copying a file to the local host from the remote host that this transport connects to, making use of any transport-specific file transfer capabilities.
If defined by a transport, this method is used by pushy.PushyClient.putfile() for copying a file from the local host to the remote host that this transport connects to, making use of any transport-specific file transfer capabilities.
The local transport is for creating and connecting to a Python interpreter on the local host. It will, by default, spawn a new Python interpreter using the same Python executable (i.e. sys.executable). The pushy.transport.local module defines a single class, Popen, which provides the local transport.
local Address Format
The address format for the local transport is simply local:
>>> import pushy
>>> con = pushy.connect("local:")
Defines the local transport, for creating and connecting to new Python interpreters on the local host.
Implements pushy.transport.BaseTransport.getfile(), calling shutil.copyfile() to perform the copy.
Implements pushy.transport.BaseTransport.putfile(), calling shutil.copyfile() to perform the copy.
Example
In this example we create a new local connection. As we can see from the parent ID of the “remote” process, it is a subprocess of the main Python interpreter.
>>> import os, platform
>>> platform.node()
'fork'
>>> os.getpid()
2386
>>> import pushy
>>> con = pushy.connect("local:")
>>> con.modules.platform.node()
'fork'
>>> con.modules.os.getppid()
2386
The primary driver for Pushy’s inception, the ssh transport provides a means of creating and connecting to a new Python interpreter on a remote host, via SSH (Secure Shell). Not only is the remote Python interpreter started up on the fly, but Pushy doesn’t need to be installed on the remote host, and nothing is transferred onto the remote filesystem. The ssh transport makes Pushy a safe alternative to traditional nailed-up, privileged services.
ssh Address Format
The address format for the ssh transport is ssh::<hostname>, where <hostname> is substituted with the hostname (or IP address) of the remote host to connect to.
>>> import pushy
>>> con = pushy.connect("ssh:my.remotehost.com")
It is possible to specify an alternative port, and specify the username and password. See Popen for more information on the parameters.
Defines the ssh transport, for creating and connecting to new Python interpreters on a remote host, via SSH (Secure Shell). Pushy is able to connect via SSH using either Paramiko, or, if available, a native SSH client, such as those provided by OpenSSH and PuTTY.
The username and password arguments may be omitted, in which case the current username will be used, and no password will be provided. In the absence of a password, public-key authentication will be attempted.
Parameters: |
|
---|
Implements pushy.transport.BaseTransport.getfile(), using SFTP (Secure File Transfer Protocol) to perform the copy.
Implements pushy.transport.BaseTransport.putfile(), using SFTP to perform the copy.
Whilst the ssh transport works perfectly well with SSH daemons on Microsoft Windows, it is not typical for systems running Windows to have an SSH daemon installed. The smb transport allows one to connect to a Windows system by installing a named pipe server, running as a Windows service. With the appropriate permissions, it is possible to remotely install a Windows service. Pushy does not yet have this feature, but it is planned for a future release.
smb Address Format
The address format for the smb transport is smb::<hostname>, where <hostname> is substituted with the hostname (or IP address) of the remote host to connect to.
>>> import pushy
>>> con = pushy.connect("smb:my.remotehost.com")
It is possible to specify the username and password, and the authenticaton domain. See Popen for more information on the parameters.
Defines the smb transport, for creating and connecting to new Python interpreters on a remoe host, via Microsoft Windows Named Pipes (SMB). Pushy is able to connect using native Microsoft Windows API calls, if the client is running on Microsoft Windows, and the ctypes module is available. Otherwise, Pushy will fall back to Impacket’s SMB module if it is available.
Parameters: |
|
---|
Sometimes you really do just want a long-lived server, and that’s what the daemon transport is for. In conjunction with pushy.server.run(), the daemon transport allows one to connect to a long-lived Python interpreter via a TCP/IP socket.
daemon Address Format
The address format for the daemon transport is daemon::<hostname>, where <hostname> is substituted with the hostname (or IP address) of the remote host to connect to.
>>> import pushy
>>> con = pushy.connect("daemon:my.remotehost.com")
It is possible to specify an alternative port. See Popen for more information on the parameters.
Note
The command argument is ignored by the daemon transport, as there is no need to create a new Python interpreter.
Parameters: |
|
---|
Example
First, start a Pushy daemon server:
$ hostname
fork
$ python -m pushy.server
And now we can create a daemon transport connection:
>>> import pushy
>>> con = pushy.connect("daemon:fork")