TIL how to use Erlang's FTP library in Elixir

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

# starts a connection

# 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

# 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)


Seems pretty straightforward!


Cool! Also, super useful:

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

1 Like