Skip to content

Commit

Permalink
[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-163]
Browse files Browse the repository at this point in the history
add SFTPClient.close()
add SFTPClient.close() and add a simple little unit test for it.
  • Loading branch information
Robey Pointer committed Apr 18, 2005
1 parent 29a5381 commit 89ccac6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions paramiko/sftp_client.py
Expand Up @@ -74,6 +74,14 @@ def from_transport(selfclass, t):
return selfclass(chan)
from_transport = classmethod(from_transport)

def close(self):
"""
Close the SFTP session and its underlying channel.
@since: 1.4
"""
self.sock.close()

def listdir(self, path):
"""
Return a list containing the names of the entries in the given C{path}.
Expand Down
17 changes: 16 additions & 1 deletion tests/test_sftp.py
Expand Up @@ -63,6 +63,7 @@
FOLDER = os.environ.get('TEST_FOLDER', 'temp-testing')

sftp = None
tc = None
g_big_file_test = True


Expand Down Expand Up @@ -101,7 +102,7 @@ def init(hostname, username, keyfile, passwd):
init = staticmethod(init)

def init_loopback():
global sftp
global sftp, tc

socks = LoopSocket()
sockc = LoopSocket()
Expand Down Expand Up @@ -144,6 +145,20 @@ def test_1_file(self):
finally:
sftp.remove(FOLDER + '/test')

def test_1a_close(self):
"""
verify that closing the sftp session doesn't do anything bad, and that
a new one can be opened.
"""
global sftp
sftp.close()
try:
sftp.open(FOLDER + '/test2', 'w')
self.fail('expected exception')
except:
pass
sftp = paramiko.SFTP.from_transport(tc)

def test_2_write(self):
"""
verify that a file can be created and written, and the size is correct.
Expand Down

0 comments on commit 89ccac6

Please sign in to comment.