Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An example ftp session using Elixir?

Tags:

elixir

I have been scouring the docs but I can't wrap my head about doing ftp in Elixir. Can someone please help give me a working example ?

like image 359
Muhammad Lukman Low Avatar asked Apr 27 '15 07:04

Muhammad Lukman Low


2 Answers

There's an example that shows how to use the Erlang FTP Client Library in the official Erlang documentation. Here's an (untested) translation to Elixir:

:inets.start
{:ok, pid} = :inets.start(:ftpc, host: 'erlang.org')
:ftp.user(pid, 'guest', 'password')
:ftp.pwd(pid)
:ftp.cd(pid, 'appl/examples')
:ftp.lpwd(pid)
:ftp.lcd(pid, '/home/eproj/examples')
:ftp.recv(pid, 'appl.erl')
:inets.stop(:ftpc, pid)
like image 56
Patrick Oscity Avatar answered Sep 21 '22 22:09

Patrick Oscity


There's a new example:
http://erlang.org/doc/apps/ftp/ftp_client.html

1> ftp:start().
ok
2> {ok, Pid} = ftp:start_service([{host, "erlang.org"}]).
{ok,<0.22.0>}
3> ftp:user(Pid, "guest", "password").
ok
4> ftp:pwd(Pid).
{ok, "/home/guest"}
5> ftp:cd(Pid, "appl/examples").
ok
6> ftp:lpwd(Pid).
{ok, "/home/fred"}.
7> ftp:lcd(Pid, "/home/eproj/examples").
ok
8> ftp:recv(Pid, "appl.erl").
ok
9> ftp:stop_service(Pid).
ok
10> ftp:stop().
ok
like image 38
Alexander Meshkov Avatar answered Sep 18 '22 22:09

Alexander Meshkov