Skip to content

Instantly share code, notes, and snippets.

@exarkun
Created July 12, 2013 15:31
Show Gist options
  • Save exarkun/5985343 to your computer and use it in GitHub Desktop.
Save exarkun/5985343 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
if __name__ == '__main__':
import sys
import sftpclient_ssh
from twisted.internet.task import react
react(sftpclient_ssh.main, sys.argv[1:])
from twisted.internet.protocol import Protocol
from twisted.internet.endpoints import connectProtocol
from twisted.conch.endpoints import SSHSubsystemClientEndpoint
from twisted.conch.ssh.filetransfer import FileTransferClient
from echoclient_ssh import ConnectionParameters
def main(reactor, *argv):
parameters = ConnectionParameters.fromCommandLine(reactor, argv)
endpoint = parameters.endpointForCommand(b"/bin/cat")
d = connectProtocol(endpoint, Protocol())
def gotConnection(proto):
conn = proto.transport.conn
transferProto = FileTransferClient()
e = SSHSubsystemClientEndpoint.existingConnection(conn, b"sftp")
d2 = connectProtocol(e, transferProto)
d2.addCallback(lambda proto: proto.makeDirectory("/tmp/foo", {}))
return d2
d.addCallback(gotConnection)
return d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment