[][src]Struct openssh::Sftp

pub struct Sftp<'s> { /* fields omitted */ }

A file-oriented channel to a remote host.

You likely want Sftp::write_to and Sftp::read_from.

Implementations

impl<'s> Sftp<'s>[src]

pub async fn can<'_>(
    &'_ mut self,
    mode: Mode,
    path: impl AsRef<Path>
) -> Result<(), Error>
[src]

Check that the given file can be opened in the given mode.

This method does not change the remote file system, except where opening a file for read/write alone causes changes (like the "last accessed" timestamp).

Note that this function is potentially racy. The permissions on the server could change between when you check and when you start a subsequent operation, causing it to fail. It can also produce false positives, such as if you are checking whether you can write to a file on a read-only file system that you still have write permissions on.

Operations like read_from and write_to internally perform similar checking to this method, so you do not need to call can before calling those methods. The checking performed by write_to can also test its permissions by actually attemping to create the remote file (since it is about to create one anyway), so its checking is more reliable than what can can provide.

pub async fn write_to<'_>(
    &'_ mut self,
    path: impl AsRef<Path>
) -> Result<RemoteFile<'s>, Error>
[src]

Open the remote file at path for writing.

If the remote file exists, it will be truncated. If it does not, it will be created.

Note that some errors may not propagate until you call close. This method internally performs similar checks to can though, so you should not need to call can before calling this method.

Examples

use std::io::prelude::*;

// connect to a remote host and get an sftp connection
let session = Session::connect("host", KnownHosts::Strict).await?;
let mut sftp = session.sftp();

// open a file for writing
let mut w = sftp.write_to("test_file").await?;

// write something to the file
use tokio::io::AsyncWriteExt;
w.write_all(b"hello world").await?;

// flush and close the remote file, absorbing any final errors
w.close().await?;

pub async fn append_to<'_>(
    &'_ mut self,
    path: impl AsRef<Path>
) -> Result<RemoteFile<'s>, Error>
[src]

Open the remote file at path for appending.

If the remote file exists, it will be appended to. If it does not, it will be created.

Note that some errors may not propagate until you call close. This method internally performs similar checks to can though, so you should not need to call can before calling this method.

Examples

use std::io::prelude::*;

// connect to a remote host and get an sftp connection
let session = Session::connect("host", KnownHosts::Strict).await?;
let mut sftp = session.sftp();

// open a file for appending
let mut w = sftp.append_to("test_file").await?;

// write will append to the file
use tokio::io::AsyncWriteExt;
w.write_all(b"hello world").await?;

// flush and close the remote file, absorbing any final errors
w.close().await?;

pub async fn read_from<'_>(
    &'_ mut self,
    path: impl AsRef<Path>
) -> Result<RemoteFile<'s>, Error>
[src]

Open the remote file at path for reading.

Note that some errors may not propagate until you call close. This method internally performs similar checks to can though, so you should not need to call can before calling this method.

Examples

use std::io::prelude::*;

// connect to a remote host and get an sftp connection
let session = Session::connect("host", KnownHosts::Strict).await?;
let mut sftp = session.sftp();

// open a file for reading
let mut r = sftp.read_from("/etc/hostname").await?;

// write something to the file
use tokio::io::AsyncReadExt;
let mut contents = String::new();
r.read_to_string(&mut contents).await?;

// close the remote file, absorbing any final errors
r.close().await?;

Trait Implementations

impl<'s> Clone for Sftp<'s>[src]

impl<'s> Debug for Sftp<'s>[src]

Auto Trait Implementations

impl<'s> RefUnwindSafe for Sftp<'s>

impl<'s> Send for Sftp<'s>

impl<'s> Sync for Sftp<'s>

impl<'s> Unpin for Sftp<'s>

impl<'s> UnwindSafe for Sftp<'s>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,