Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions async-ssh2-lite/src/sftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,36 @@ impl<S> AsyncFile<S>
where
S: AsyncSessionStream + Send + Sync + 'static,
{
pub async fn setstat(&mut self, stat: FileStat) -> Result<(), Error> {
self.stream
.rw_with(|| self.inner.setstat(stat.clone()), &self.sess)
.await
}

pub async fn stat(&mut self) -> Result<FileStat, Error> {
self.stream.rw_with(|| self.inner.stat(), &self.sess).await
}

pub async fn statvfs(&mut self) -> Result<libssh2_sys::LIBSSH2_SFTP_STATVFS, Error> {
self.stream
.rw_with(|| self.inner.statvfs(), &self.sess)
.await
}

pub async fn readdir(&mut self) -> Result<(PathBuf, FileStat), Error> {
self.stream
.rw_with(|| self.inner.readdir(), &self.sess)
.await
}

pub async fn fsync(&mut self) -> Result<(), Error> {
self.stream.rw_with(|| self.inner.fsync(), &self.sess).await
}

#[doc(hidden)]
pub async fn close(&mut self) -> Result<(), Error> {
self.stream.rw_with(|| self.inner.close(), &self.sess).await
}
}

mod impl_futures_util {
Expand Down
8 changes: 8 additions & 0 deletions async-ssh2-lite/tests/integration_tests/sftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@ async fn __run__session__sftp<S: AsyncSessionStream + Send + Sync + 'static>(
let remote_path = PathBuf::from("/tmp").join(format!("sftp_{}", Uuid::new_v4()));

sftp.create(&remote_path).await?;

let file_stat = sftp.stat(&remote_path).await?;
println!("sftp file_stat:{:?}", file_stat);

let mut sftp_file = sftp.open(&remote_path).await?;
let file_stat_for_file = sftp_file.stat().await?;
println!("sftp file_stat_for_file:{:?}", file_stat_for_file);
sftp_file.close().await?;
assert_eq!(file_stat, file_stat_for_file);

sftp.unlink(&remote_path).await?;

let list = sftp.readdir(&PathBuf::from("/")).await?;
Expand Down