I understand this is an old question, but hopefully others will find it useful:
lftpc is the “Erlang lightweight FTP client” modeled after lhttpc and dlhttpc , which we have used in production over the past 6 months or so.
This is not well documented right now, but here is an example using test.rebex.net :
1> lftpc:start(). ok 2> {ok, {_, _, Socket}} = lftpc:connect("test.rebex.net", 21, []). {ok,{undefined,{220,[<<"FTP on test.rebex.net ready...">>]}, <0.65.0>}} 3> lftpc:login(Socket, [{username, <<"demo">>}, {password, <<"password">>}], infinity, []). {ok,[{undefined,{331,[<<"Password required for demo.">>]}, undefined}, {undefined,{230,[<<"User demo logged in.">>]},undefined}]} 4> lftpc:cd(Socket, <<"pub">>, infinity, []). {ok,{undefined,{250, [<<"CWD command successful. \"/pub\" is current directory.">>]}, undefined}}
By default, there are no decoders to control or connect data. Therefore, when we list the directory containing 2 files: example and test , we will return:
5> lftpc:nlist(Socket, infinity, []). {ok,{{150, [<<"Data connection accepted from 173.198.175.141:53504; transfer starting.">>]}, {226,[<<"Transfer ok.">>]}, [<<"example\r\ntest\r\n">>]}}
We can specify data_decoder :
6> lftpc:nlist(Socket, infinity, [{partial_download, []}, {data_decoder, lftpc_format:nlst_decoder()}]). {ok,{{150, [<<"Data connection accepted from 127.0.0.1:54359; transfer starting.">>]}, {226,[<<"Transfer ok.">>]}, [[<<"example">>,<<"test">>]]}}
We can also specify partial_download to get the data in pieces:
7> {ok, {_, Download}} = lftpc:nlist(Socket, infinity, [{partial_download, []}, {data_decoder, lftpc_format:nlst_decoder()}]). {ok,{{150, [<<"Data connection accepted from 127.0.0.1:54403; transfer starting.">>]}, <0.86.0>}} 8> receive {data_part, Download, Data} -> Data end. [<<"example">>,<<"test">>] 9> receive {ftp_eod, Download, Message} -> Message end. {226,[<<"Transfer ok.">>]}
Take a look at the main src/lftpc.erl , there are high-level and low-level functions depending on your needs. You can always go down to lftpc:request/3,4,5,6 and lftpc:start_transfer/3 to do something normal.