sftp_ex v0.2.6 SftpEx
Functions for transferring and managing files through SFTP
Summary
Functions
Creates a Connection struct if the connection is successful, else will return {:error, reason}
Stops the SSH application
Download a file given the connection and remote_path Returns {:ok, data}, {:error, reason}
Gets the type given a remote path. Types: connection = Connection remote_path = handle() or string()
Lists the contents of a directory given a connection a handle or remote path
Types: connection = Connection remote_path = string() or handle()
Lists the contents of a directory given a connection a handle or remote path Types: connection = Connection remote_path = string()
Opens a file or directory given a connection and remote_path
Renames a file or directory
Removes a file from the server. Types:
connection = Connection
file = string()
Removes a directory and all files within it Types:
connection = Connection
remote_path = string()
Types: connection = Connection remote_path = handle() or string()
Creates an SFTP stream by opening an SFTP connection and opening a file in read or write mode
Uploads data to a remote path via SFTP Returns :ok, or {:error, reason}
Functions
Creates a Connection struct if the connection is successful, else will return {:error, reason}
A connection struct will contain the
channel_pid = pid()
connection_pid = pid()
host = string()
port = integer()
opts = [{Option, Value}]
Default values are set for the following options:
user_interaction: false, silently_accept_hosts: true, rekey_limit: 1000000000000, port: 22
*NOTE: The only required option is ‘:host’
The rekey_limit value is set at a large amount because the Erlang library creates an exception when the server is negotiating a rekey. Setting the value at a high number of bytes will avoid a rekey event occurring.
Other available options can be found at http://erlang.org/doc/man/ssh.html#connect-3
Returns {:ok, Connection}, or {:error, reason}
Download a file given the connection and remote_path Returns {:ok, data}, {:error, reason}
Gets the type given a remote path. Types: connection = Connection remote_path = handle() or string()
type = :device | :directory | :regular | :other
Returns {:ok, type}, or {:error, reason}
Lists the contents of a directory given a connection a handle or remote path
Types: connection = Connection handle = handle() remote_path = string()
Returns {:ok, [Filename]}, or {:error, reason}
Types: connection = Connection remote_path = string() or handle()
Returns {:ok, File.Stat}, or {:error, reason}
Lists the contents of a directory given a connection a handle or remote path Types: connection = Connection remote_path = string()
Returns :ok, or {:error, reason}
Opens a file or directory given a connection and remote_path
Types: connection = Connection handle = handle() remote_path = string()
Returns {:ok, handle}, or {:error, reason}
Renames a file or directory
Types:
connection = Connection
old_name = string()
new_name = string()
Returns {:ok, handle}, or {:error, reason}
Removes a file from the server. Types:
connection = Connection
file = string()
Returns :ok, or {:error, reason}
Removes a directory and all files within it Types:
connection = Connection
remote_path = string()
Returns :ok, or {:error, reason}
Types: connection = Connection remote_path = handle() or string()
Returns size as {:ok, integer()} or {:error, reason}
Creates an SFTP stream by opening an SFTP connection and opening a file in read or write mode.
Below is an example of reading a file from a server.
An example of writing a file to a server is the following.
stream = File.stream!(“filename.txt”)
|> Stream.into(SftpEx.stream!(connection,"/home/path/filename.txt"))
|> Stream.run
This follows the same pattern as Elixir IO streams so a file can be transferred from one server to another via SFTP as follows.
stream = SftpEx.stream!(connection,”/home/path/filename.txt”) |> Stream.into(SftpEx.stream!(connection2,”/home/path/filename.txt”)) |> Stream.run
Types: connection = Connection remote_path = string()
Returns SFTP.Stream