sftp_toolkit v1.0.0 SFTPToolkit.Download

Module containing functions that ease downloading data from the SFTP server.

Link to this section Summary

Functions

Downloads a single file by reading it in chunks to avoid loading whole file into memory as :ssh_sftp.read_file/3 does by default

Link to this section Functions

Link to this function

download_file(sftp_channel_pid, remote_path, local_path, options \\ [])
download_file(pid(), Path.t(), Path.t(),
  operation_timeout: timeout(),
  chunk_size: pos_integer(),
  remote_mode: [:read | :write | :creat | :trunc | :append | :binary],
  local_mode: [File.mode()]
) :: :ok | {:error, any()}

Downloads a single file by reading it in chunks to avoid loading whole file into memory as :ssh_sftp.read_file/3 does by default.

Arguments

Expects the following arguments:

  • sftp_channel_pid - PID of the already opened SFTP channel,
  • remote_path - remote path to the file on the SFTP server,
  • local_path - local path to the file,
  • options - additional options, see below.

Options

  • operation_timeout - SFTP operation timeout (it is a timeout per each SFTP operation, not total timeout), defaults to 5000 ms,
  • chunk_size - chunk size in bytes, defaults to 32KB,
  • remote_mode - mode used while opening the remote file, defaults to [:read, :binary], see :ssh_sftp.open/3 for possible values,
  • local_mode - mode used while opening the local file, defaults to [:write, :binary], see File.open/2 for possible values.

Return values

On success returns :ok.

On error returns {:error, reason}, where reason might be one of the following:

  • {:local_open, info} - the File.open/2 on the local file failed,
  • {:remote_open, info} - the :ssh_sftp.open/4 on the remote file failed,
  • {:download, {:read, info}} - the IO.binwrite/2 on the local file failed,
  • {:download, {:write, info}} - the :ssh_sftp.read/4 on the remote file failed,
  • {:local_close, info} - the File.close/1 on the local file failed,
  • {:remote_close, info} - the :ssh_sftp.close/2 on the remote file failed.