README.md

# SftpStage

Faster SFTP file downloader

## Installation

```elixir
def deps do
  [
    {:sftp_stage, "~> 0.1.0"}
  ]
end
```


## Overview

SftpStage makes use of parallel read requests to overcome the [limitations](https://daniel.haxx.se/blog/2010/12/08/making-sftp-transfers-fast/) of SFTP protocol. SftpStage implements [GenStage](https://hexdocs.pm/gen_stage/GenStage.html).

Simple way to use SftpStage is to connect with [Flow](https://hexdocs.pm/flow/Flow.html)

```elixir
  opts = %{
    host: "127.0.0.1",
    port: 22,
    sftp_opts: [
      user: 'admin',
      password: 'pass',
      user_interaction: false,
      silently_accept_hosts: true,
      rekey_limit: 1_000_000_000_000
    ],
    file_path: "/users/admin/reports/2019-12-01.zip"
  }

  Flow.from_specs([{SftpStage, opts}])
  |> Stream.into(File.stream!("reports.zip"))
  |> Stream.run()
```

Since SftpStage is just a GenStage producer you can also use it with [GenStage.stream](https://hexdocs.pm/gen_stage/GenStage.html#stream/2) or connect to your GenStage consumer.

## Options

* `host`: <kbd>required</kbd> server hostname

* `port`: server port number. Defaults to `22`

* `sftp_opts`: <kbd>required</kbd> SFTP/SSH options. This keyword list is passed to Erlang library. See Erlang [documentation](http://erlang.org/doc/man/ssh_sftp.html#start_channel-3)

* `file_path`: <kbd>required</kbd> Remote file absolute path

* `max_concurrent_requests`: Maximum number of allowed concurrent requests to server at a time. Defaults to `10`