Alternative FTP client libraries for Erlang

The OTP library has at least two HTTP client libraries for Erlang in addition to httpc (which is usually seen as buggy and awkward): ibrowse and lhttpc . Are there any similar ftp alternatives?

+6
erlang ftp
source share
2 answers

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.

+3
source share

You may or may not find this useful, but I can explain what we have done for our project. We especially needed to use sftp in Erlang and found that it was faulty and incompatible with some server configurations. In the end, we created a simple ftp / sftp client in Java using jsch and using JInterface to connect it to Erlang. We spent a couple of days trying to fight the Erlang ftp protocol implementation and get it to work, but eventually ended up developing and testing the Java implementation using JInterface in just a few hours. Good luck.

http://www.jcraft.com/jsch/

+2
source share

All Articles