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

Added initial SFTP implementation using SSH.NET #15477

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

itsWindows11
Copy link
Contributor

@itsWindows11 itsWindows11 commented May 26, 2024

Resolved / Related Issues

To prevent extra work, all changes to the Files codebase must link to an approved issue marked as Ready to build. Please insert the issue number following the hashtag with the issue number that this Pull Request resolves.

Steps used to test these changes

Stability is a top priority for Files and all changes are required to go through testing before being merged into the repo. Please include a list of steps that you used to test this PR.

Currently waiting for #8974 to be implemented (since the current way of hooking filesystems to the UI is a total mess I cannot figure out) along with #15473, this PR is to lay the groundwork for resolving #2407 and will be marked as ready when everything is finished.

@0x5bfa
Copy link
Member

0x5bfa commented May 26, 2024

This is around Storage Abstraction and it'll take a huge amount of time to get this abstraction ready for actual use.
@yaira2 we might as well merge like we have done as leave until finish.
If you agree, I'll take a look and leave a review.

@0x5bfa 0x5bfa self-requested a review May 26, 2024 16:04
@yaira2
Copy link
Member

yaira2 commented May 26, 2024

Sounds good

Copy link
Member

@0x5bfa 0x5bfa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise!

You seem to have implemented for BaseStorageItem.
Is that working well?
If so, how did you validate/use SFTP storage?

@itsWindows11
Copy link
Contributor Author

It's a draft for a reason 🙃 I'll do the testing outside of Files in a separate project, until I can figure out the UI part.

I've seen what's implemented for FTP support and tried to go for a similar implementation since it's pretty much the only non-shell-based storage implementation here with different protocols (AFAIK)

@yaira2
Copy link
Member

yaira2 commented Sep 8, 2024

@itsWindows11 what the status of this PR?

@0x5bfa
Copy link
Member

0x5bfa commented Sep 8, 2024

Storage abstraction won't be implemented until the next year unless someone take over in Files and given OwlCore's progress. I think we should wrap up in order to merge.

@tmds
Copy link

tmds commented Oct 4, 2024

Hi all, I wonder if you may be open to use Tmds.Ssh to implement this feature?

The SftpClient is fully async and it has methods that match well with what you need. Additionally, the upload/download methods are optimized to parallelize the transfer while keeping the overall .NET memory allocations low.

I'd be interested in any feedback you have while using the library.

@itsWindows11
Copy link
Contributor Author

Sounds like a better option, but my SSH.NET issue regarding async IO support seems to be addressed so I don't think there's a need to switch.

The main blocker is the storage abstraction though, we either need to get this merged with switching the methods to be async and someone completes the integration, or wait until we can use OwlCore.Storage w/ extensions on the Files end.

@tmds
Copy link

tmds commented Oct 6, 2024

@itsWindows11 the reason to consider switching could be performance. From the limited comparisons I did, Tmds.Ssh was considerably faster.

@itsWindows11
Copy link
Contributor Author

itsWindows11 commented Oct 11, 2024

I have just played around a bit with your library while working on an OwlCore.Storage wrapper.

Besides tmds/Tmds.Ssh#239, there are a few issues I've encountered with the library, especially when enumerating contents in directories:

  • In mysterious cases that I can't seem to investigate, an InvalidOperationException is randomly thrown when trying to enumerate items in a directory (says something about object state being invalid when enumerating).
  • Authentication requires a lot of work than required when compared to SSH.NET, specifically around known hosts & certificate management.

@tmds
Copy link

tmds commented Oct 11, 2024

I have just played around a bit with your library while working on an OwlCore.Storage wrapper.

@itsWindows11 thank you for making some time to check it out!

Besides tmds/Tmds.Ssh#239

I will take a look.

In mysterious cases that I can't seem to investigate, an InvalidOperationException is randomly thrown when trying to enumerate items in a directory (says something about object state being invalid when enumerating).

I have no clue what this might be about. Do you have an exception message and stacktrace?

Authentication requires a lot of work than required when compared to SSH.NET, specifically around known hosts & certificate management.

To do the same as SSH.NET, you can set sshClientSettings.HostAuthentication = delegate { return true; }. This isn't secure. It's similar to accepting an untrusted certificate in your browser.

@yaira2 yaira2 closed this Oct 14, 2024
@yaira2 yaira2 reopened this Oct 14, 2024
@tmds
Copy link

tmds commented Oct 21, 2024

I have no clue what this might be about. Do you have an exception message and stacktrace?

@itsWindows11 if you have some time for it, this would be very useful to help me understand the issue.

It's similar to accepting an untrusted certificate in your browser.

You may want to address this regardless of the SSH library you are using. You could for example also store the sha256fingerprint of the ssh server. To help the user, you can use the SSH library to retrieve the fingerprint.

For reference, this is the ssh UX:

❯ ssh github.com
The authenticity of host 'github.com (140.82.121.4)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

(Note that Tmds.Ssh can use the OpenSSH known_hosts file so it shares the trust information with other ssh tools used on the system.)

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

Successfully merging this pull request may close these issues.

4 participants