Open
Description
I use asyncssh to download files from remote servers/network devices and would like to have an option to safely interrupt process.
There is my code:
async def download(host: str):
path = Path(f"./download/{host}")
path.mkdir(parents=True, exist_ok=True)
try:
async with asyncssh.connect(host) as conn:
print(f"{host}: connected")
await asyncssh.scp(
(conn, HUGE_FILE), path,
)
except Exception as exc:
print(f"{host}: {exc.__class__}: {exc}")
except asyncio.exceptions.CancelledError as exc:
print(f"{host}: {exc.__class__}: {exc}")
raise
finally:
print(f"{host}: done")
async def main():
await asyncio.gather(
download(HOST),
)
try:
asyncio.run(main())
except KeyboardInterrupt:
print(f"Interrupted!!!")
It works fine when I download file from linux server:
[conn=0, chan=0] Received 16384 SCP data bytes
[conn=0, chan=0] Received 16384 SCP data bytes <=== ctrl-C is pressed here
^C[conn=0, chan=0] Stopping remote SCP
[conn=0, chan=0] Closing channel
[conn=0, chan=0] Received exit signal PIPE
[conn=0, chan=0] Core dumped: False
[conn=0, chan=0] Message:
[conn=0, chan=0] Received channel close
[conn=0, chan=0] Channel closed
[conn=0] Closing connection
[conn=0] Sending disconnect: Disconnected by application (11)
[conn=0] Connection closed
172.31.0.8: <class 'asyncio.exceptions.CancelledError'>:
172.31.0.8: done
Interrupted!!!
but when I download file from juniper router it stuck during channel closing:
[conn=0, chan=0] Received 16384 SCP data bytes
[conn=0, chan=0] Received 16384 SCP data bytes <=== ctrl-C is pressed here
^C[conn=0, chan=0] Stopping remote SCP
[conn=0, chan=0] Closing channel <=== stuck here and need to press ctrl-C again
^C[conn=0] Closing connection
[conn=0, chan=0] Closing channel
[conn=0] Sending disconnect: Disconnected by application (11)
[conn=0] Connection closed
[conn=0, chan=0] Closing channel due to connection close
[conn=0, chan=0] Channel closed
172.31.0.48: <class 'asyncio.exceptions.CancelledError'>:
172.31.0.48: done
Interrupted!!!
As I understand remote device doesn't close channel correctly, but is any option to force it and don't wait another side?
Metadata
Metadata
Assignees
Labels
No labels