def test_sftp_session(server):
for uid in server.users:
target_dir = tempfile.mkdtemp()
target_fname = os.path.join(target_dir, "foo")
assert not os.access(target_fname, os.F_OK)
with server.client(uid) as c:
sftp = c.open_sftp()
sftp.put(__file__, target_fname, confirm=True)
assert files_equal(target_fname, __file__)
second_copy = os.path.join(target_dir, "bar")
assert not os.access(second_copy, os.F_OK)
sftp.get(target_fname, second_copy)
assert files_equal(target_fname, second_copy)
dir_contents = sftp.listdir(target_dir)
assert len(dir_contents) == 2
assert "foo" in dir_contents
assert "bar" in dir_contents
with raises(IOError):
sftp.listdir("/123_no_dir")
评论列表
文章目录