Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to close SftpChannel? #1305

Closed
alanhe421 opened this issue Jun 4, 2023 · 3 comments
Closed

How to close SftpChannel? #1305

alanhe421 opened this issue Jun 4, 2023 · 3 comments
Labels

Comments

@alanhe421
Copy link

alanhe421 commented Jun 4, 2023

For example, here I use a connection to obtain an SFTP channel. When I'm in the middle of an upload and I want to cancel it without closing the SSH connection, my understanding is that I can simply close this channel, right?

image

I see that the close method of the channel has two parameters during debugging, but I'm not sure what should be passed specifically.

image

@alanhe421 alanhe421 changed the title how to close SftpChannel? How to close SftpChannel? Jun 4, 2023
@alanhe421 alanhe421 reopened this Jun 4, 2023
@mscdex
Copy link
Owner

mscdex commented Jun 4, 2023

sftp.end() should close the channel.

@mscdex mscdex added the question label Jun 4, 2023
@alanhe421
Copy link
Author

alanhe421 commented Jun 4, 2023

Thank you, I understand. So, sftp.end does not close the SSH connection; it only closes the specific channel.

I would like to ask, based on my previous description, if closing the channel and reestablishing it is a recommended approach for implementing upload cancellation. I'm not sure if FileZilla or other applications use this approach.

The fundamental question is whether each file transfer is conducted through a separate channel. If each file transfer does indeed use a separate channel and closing the channel after a file is completed is the standard practice, then it is reasonable to cancel the transfer by closing the channel. However, if this is not the case and multiple file transfers share the same channel, then there may be an issue with your approach.

@mscdex
Copy link
Owner

mscdex commented Jun 4, 2023

Each call to ssh.sftp() is a separate channel. If you are performing multiple transfers on the same SFTP channel, then simply only stop the transfer you want. If you're using sftp.fast*(), you either need to create your own solution and/or keep an eye on this feature request. Otherwise if you're using a file stream, you simply just need to destroy it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants