TIL how to use Erlang's FTP library in Elixir

host = 'ftp.thing.org'
username = 'your_username'
password = 'your_password'

# starts a connection
:inets.start

# connects to host and assigns pid
{:ok, pid} = :inets.start(:ftpc, host: host)

# logs into host with username and password
:ftp.user(pid, username, password)

# returns current working directory
:ftp.pwd(pid)

# cds into specific directory
:ftp.cd(pid, 'directory/resources')

# receives file called 'file.txt' which is in directory/resources and saves to current local working directory
:ftp.recv(pid, 'file.txt')

# receives file called 'file.txt' and saves to specific local directory
:ftp.recv(pid, 'file.txt', './myLocalDirectory/')

# kills the connection to host
:inets.stop(:ftpc, pid)

http://erlang.org/doc/apps/inets/ftp_client.html#id62977

Seems pretty straightforward!

6 Likes

Cool! Also, super useful:

:inets.send_bin(pid, "some contents", '/path/to/remote/file').

1 Like