-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from AspectUnk/impl-client
Implementation for client side
- Loading branch information
Showing
26 changed files
with
1,957 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
# Russh SFTP | ||
SFTP subsystem supported server and client for [Russh](https://github.com/warp-tech/russh)\ | ||
Implemented according to [version 3 specifications](https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt) (most popular) | ||
SFTP subsystem supported server and client for [Russh](https://github.com/warp-tech/russh) and more!\ | ||
Crate can provide compatibility with anything that can provide the raw data stream in and out of the subsystem channel.\ | ||
Implemented according to [version 3 specifications](https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02) (most popular). | ||
|
||
## Examples | ||
- [Client example](https://github.com/AspectUnk/russh-sftp/blob/master/examples/client.rs) | ||
- [Simple server](https://github.com/AspectUnk/russh-sftp/blob/master/examples/server.rs) | ||
- ~~Fully implemented server~~ | ||
- ~~Client example~~ | ||
|
||
## What's ready? | ||
- [x] Basic packets | ||
- [x] Extended packets | ||
- [x] Simplification for file attributes | ||
- [x] Client side | ||
- [x] Client example | ||
- [x] Server side | ||
- [x] Simple server example | ||
- [ ] Error handler (unlike specification) | ||
- [x] Extension support: `[email protected]`, `[email protected]` | ||
- [ ] Full server example | ||
- [ ] Unit tests | ||
- [ ] Workflow | ||
- [ ] Client side | ||
- [ ] Client example | ||
|
||
## Some words | ||
Thanks to [@Eugeny](https://github.com/Eugeny) (author of the [Russh](https://github.com/warp-tech/russh)) for his prompt help and finalization of Russh API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use std::io; | ||
use thiserror::Error; | ||
use tokio::sync::mpsc::error::SendError as MpscSendError; | ||
use tokio::sync::oneshot::error::RecvError as OneshotRecvError; | ||
use tokio::time::error::Elapsed as TimeElapsed; | ||
|
||
use crate::error; | ||
use crate::protocol::Status; | ||
|
||
/// Enum for client errors | ||
#[derive(Debug, Clone, Error)] | ||
pub enum Error { | ||
/// Contains an error status packet | ||
#[error("{}: {}", .0.status_code, .0.error_message)] | ||
Status(Status), | ||
/// Any errors related to I/O | ||
#[error("I/O: {0}")] | ||
IO(String), | ||
/// Time limit for receiving response packet exceeded | ||
#[error("Timeout")] | ||
Timeout, | ||
/// Occurs due to exceeding the limits set by the `[email protected]` extension | ||
#[error("Limit exceeded: {0}")] | ||
Limited(String), | ||
/// Occurs when an unexpected packet is sent | ||
#[error("Unexpected packet")] | ||
UnexpectedPacket, | ||
/// Occurs when unexpected server behavior differs from the protocol specifition | ||
#[error("{0}")] | ||
UnexpectedBehavior(String), | ||
} | ||
|
||
impl From<Status> for Error { | ||
fn from(status: Status) -> Self { | ||
Self::Status(status) | ||
} | ||
} | ||
|
||
impl From<io::Error> for Error { | ||
fn from(error: io::Error) -> Self { | ||
Self::IO(error.to_string()) | ||
} | ||
} | ||
|
||
impl<T> From<MpscSendError<T>> for Error { | ||
fn from(err: MpscSendError<T>) -> Self { | ||
Self::UnexpectedBehavior(format!("SendError: {}", err)) | ||
} | ||
} | ||
|
||
impl From<OneshotRecvError> for Error { | ||
fn from(err: OneshotRecvError) -> Self { | ||
Self::UnexpectedBehavior(format!("RecvError: {}", err)) | ||
} | ||
} | ||
|
||
impl From<TimeElapsed> for Error { | ||
fn from(_: TimeElapsed) -> Self { | ||
Self::Timeout | ||
} | ||
} | ||
|
||
impl From<error::Error> for Error { | ||
fn from(error: error::Error) -> Self { | ||
Self::UnexpectedBehavior(error.to_string()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::collections::VecDeque; | ||
|
||
use super::Metadata; | ||
use crate::protocol::FileType; | ||
|
||
/// Entries returned by the [`ReadDir`] iterator. | ||
#[derive(Debug)] | ||
pub struct DirEntry { | ||
file: String, | ||
metadata: Metadata, | ||
} | ||
|
||
impl DirEntry { | ||
/// Returns the file name for the file that this entry points at. | ||
pub fn file_name(&self) -> String { | ||
self.file.to_owned() | ||
} | ||
|
||
/// Returns the file type for the file that this entry points at. | ||
pub fn file_type(&self) -> FileType { | ||
self.metadata.file_type() | ||
} | ||
|
||
/// Returns the metadata for the file that this entry points at. | ||
pub fn metadata(&self) -> Metadata { | ||
self.metadata.to_owned() | ||
} | ||
} | ||
|
||
/// Iterator over the entries in a remote directory. | ||
pub struct ReadDir { | ||
pub(crate) entries: VecDeque<(String, Metadata)>, | ||
} | ||
|
||
impl Iterator for ReadDir { | ||
type Item = DirEntry; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
match self.entries.pop_front() { | ||
None => None, | ||
Some(entry) if entry.0 == "." || entry.0 == ".." => self.next(), | ||
Some(entry) => Some(DirEntry { | ||
file: entry.0, | ||
metadata: entry.1, | ||
}), | ||
} | ||
} | ||
} |
Oops, something went wrong.