Skip to content

How to either reuse or fully close asyncssh connection to sftp #444

Answered by ronf
ABO33 asked this question in Q&A
Discussion options

You must be logged in to vote

If you want to make sure the SFTP connection is fully closed, you'll probably want to change your disconnect() call to something like:

    async def disconnect(self):
        self.sftp_client.exit()
        await self.sftp_client.wait_closed()

However, this will only close the SFTP client session and not the underlying SSH connection. If you want to close the connections, you'll need to keep track of conn in your connect() call and later close that connection. This might look something like:

    async def connect(self):
        self.conn = await asyncssh.connect(**self.credentials)
        self.sftp_client = await self.conn.start_sftp_client()

    async def disconnect(self):
        self.s…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ABO33
Comment options

Answer selected by ABO33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants