Commits

ericvsmith  committed f3a5aac

Fixed embarassing typo.

  • Participants
  • Parent commits 190a007

Comments (0)

Files changed (4)

 Change log
 ==========
 
+0.2 2011-10-31 Eric V. Smith
+----------------------------
+* Removed useless tests.
+* Fixed embarassing last minute typo which broke the code.
+* Included trivil examples in README.txt. Needs much work.
+* Forbid files that contain '..' in them. This is an attempt to
+  prevent path traversal. This approach is simplistic, but it's a
+  reasonable first step and gets the job done.
+
 0.1 2011-10-31 Eric V. Smith
 ----------------------------
 * Initial release.
-===========
+=========
 scpclient
-===========
+=========
 
 A library that implements the client side of the scp (Secure Copy)
 protocol. It is designed to be used with paramiko
 (http://www.lag.net/paramiko/).
 
+Writing files
+-------------
+
+Example::
+
+    with closing(Write(ssh_client.get_transport(), '.')) as scp:
+        scp.send_file('file.txt', True)
+        scp.send_file('../../test.log', remote_filename='baz.log')
+
+        s = StringIO('this is a test')
+        scp.send(s, 'test', '0601', len(s.getvalue()))
+
+Writing directories
+-------------------
+
+Example::
+
+    with closing(WriteDir(ssh_client.get_transport(), 'subdir')) as scp:
+        scp.send_dir('../../manuals', preserve_times=True, progress=progress)
+
+Reading files
+-------------
+
+Example::
+
+    with closing(ReadDir(ssh_client.get_transport(), '.')) as scp:
+        scp.receive_dir('foo', preserve_times=True)
+
+Reading directories
+-------------------
+
+Example::
+
+    with closing(Read(ssh_client.get_transport(), '.')) as scp:
+        scp.receive('file.txt')

File scpclient.py

                  timeout=None,
                  remote_scp_command=_REMOTE_SCP_COMMAND,
                  buf_size=_DEFAULT_BUF_SIZE):
-        ReadBase.__init__(self, transport, remote_path, timeout,
+        _ReadBase.__init__(self, transport, remote_path, timeout,
                           remote_scp_command, buf_size, False)
 
 
                  timeout=None,
                  remote_scp_command=_REMOTE_SCP_COMMAND,
                  buf_size=_DEFAULT_BUF_SIZE):
-        ReadBase.__init__(self, transport, remote_path, timeout,
+        _ReadBase.__init__(self, transport, remote_path, timeout,
                           remote_scp_command, buf_size, True)
 
     def receive_dir(self, local_dirname,
         for op in scp._receive(remote_dirname):
             if _os.path.isabs(op.path):
                 raise SCPError('{0!r} is an absolute path'.format(op.path))
+            if '..' in op.path:
+                raise SCPError('{0!r} contains ".."'.format(op.path))
             path = _os.path.join(local_dirname, op.path)
             if isinstance(op, _read_file):
                 with open(path, 'wb') as fl:
 ########################################################################
 
 if __name__ == '__main__':
-    import paramiko
-    import logging
-    import time
-    from StringIO import StringIO
-    from contextlib import closing
-
-
-    def progress(filename, size, so_far):
-        print 'progress: {0} {1} {2}'.format(filename, size, so_far)
-
-    class AcceptAnyKeyPolicy(paramiko.MissingHostKeyPolicy):
-        def missing_host_key(self, client, hostname, key):
-            return
-
-
-    def ssh_connect(hostname, username, key_filename=None, password=None):
-        logging.info('ssh_connect: %r %r %r' % (hostname, username, key_filename))
-        client = paramiko.SSHClient()
-
-        # Accept any host key. Probably not the smartest thing to do
-        client.set_missing_host_key_policy(AcceptAnyKeyPolicy())
-
-        if key_filename:
-            client.connect(hostname, username=username, key_filename=key_filename, password=password, look_for_keys=False)
-        else:
-            client.connect(hostname, username=username, password=password)
-        return client
-
-
-    logging.basicConfig(level=logging.INFO)
-    with closing(ssh_connect('delmar.trueblade.com', 'robert', 'c:/home/eric/keys/foo', 'foobar')) as ssh_client:
-
-        ## with closing(Write(ssh_client.get_transport(), '.')) as scp:
-        ##     scp.send_file('pyscp.py', True)
-        ##     scp.send_file('../../unison.log', remote_filename='baz.log')
-
-        ##     s = StringIO('this is a test')
-        ##     scp.send(s, 'test', '0601', len(s.getvalue()))
-
-        ## with closing(WriteDir(ssh_client.get_transport(), 'foo')) as scp:
-        ##     scp.send_dir('../../manuals', preserve_times=True, progress=progress)
-
-#        with closing(Read(ssh_client.get_transport(), '.', buf_size=2)) as scp:
-#            scp.receive_file('testx', remote_filename='test', preserve_times=True)
-#            print scp.receive(remote_filename='test')
-
-        with closing(ReadDir(ssh_client.get_transport(), 'a')) as scp:
-            scp.receive_dir('foo', preserve_times=True)
-
-        # errors:
-        # read a directory with a normal read command
-        # write a directory with a normal write command
+    # need tests
+    pass
 from distutils.core import setup, Command
 
 setup(name='scpclient',
-      version='0.1',
+      version='0.2',
       url='https://bitbucket.org/ericvsmith/scpclient',
       author='Eric V. Smith',
       author_email='eric@trueblade.com',