Current section
Files
Jump to
Current section
Files
src/gftp@internal@command.erl
-module(gftp@internal@command).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/gftp/internal/command.gleam").
-export([to_string/1]).
-export_type([command/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-type command() :: abor |
{appe, binary()} |
auth |
clear_command_channel |
cdup |
{cwd, binary()} |
{dele, binary()} |
{eprt, binary(), integer(), gftp@mode:ip_version()} |
epsv |
feat |
{list, gleam@option:option(binary())} |
{mdtm, binary()} |
{mlsd, gleam@option:option(binary())} |
{mlst, gleam@option:option(binary())} |
{mkd, binary()} |
{nlst, gleam@option:option(binary())} |
noop |
{opts, binary(), gleam@option:option(binary())} |
{pass, binary()} |
pasv |
{pbsz, integer()} |
{port, binary()} |
{prot, gftp@internal@command@protection_level:protection_level()} |
pwd |
quit |
{rename_from, binary()} |
{rename_to, binary()} |
{rest, integer()} |
{retr, binary()} |
{rmd, binary()} |
{site, binary()} |
{size, binary()} |
{stor, binary()} |
{type, gftp@file_type:file_type()} |
{user, binary()} |
{custom, binary()}.
-file("src/gftp/internal/command.gleam", 91).
?DOC(false).
-spec encode_eprt(binary(), integer(), gftp@mode:ip_version()) -> binary().
encode_eprt(Host, Port, Ip_version) ->
Ip_version_str = case Ip_version of
v4 ->
<<"1"/utf8>>;
v6 ->
<<"2"/utf8>>
end,
<<<<<<<<<<<<"EPRT |"/utf8, Ip_version_str/binary>>/binary, "|"/utf8>>/binary,
Host/binary>>/binary,
"|"/utf8>>/binary,
(erlang:integer_to_binary(Port))/binary>>/binary,
"|"/utf8>>.
-file("src/gftp/internal/command.gleam", 100).
?DOC(false).
-spec to_string(command()) -> binary().
to_string(Command) ->
case Command of
abor ->
<<"ABOR"/utf8>>;
{appe, F} ->
<<"APPE "/utf8, F/binary>>;
auth ->
<<"AUTH TLS"/utf8>>;
cdup ->
<<"CDUP"/utf8>>;
clear_command_channel ->
<<"CCC"/utf8>>;
{cwd, D} ->
<<"CWD "/utf8, D/binary>>;
{dele, F@1} ->
<<"DELE "/utf8, F@1/binary>>;
{eprt, Host, Port, Ip_version} ->
encode_eprt(Host, Port, Ip_version);
epsv ->
<<"EPSV"/utf8>>;
feat ->
<<"FEAT"/utf8>>;
{list, P} ->
_pipe = P,
_pipe@1 = gleam@option:map(
_pipe,
fun(X) -> <<"LIST "/utf8, X/binary>> end
),
gleam@option:unwrap(_pipe@1, <<"LIST"/utf8>>);
{mdtm, P@1} ->
<<"MDTM "/utf8, P@1/binary>>;
{mkd, P@2} ->
<<"MKD "/utf8, P@2/binary>>;
{mlsd, P@3} ->
_pipe@2 = P@3,
_pipe@3 = gleam@option:map(
_pipe@2,
fun(X@1) -> <<"MLSD "/utf8, X@1/binary>> end
),
gleam@option:unwrap(_pipe@3, <<"MLSD"/utf8>>);
{mlst, P@4} ->
_pipe@4 = P@4,
_pipe@5 = gleam@option:map(
_pipe@4,
fun(X@2) -> <<"MLST "/utf8, X@2/binary>> end
),
gleam@option:unwrap(_pipe@5, <<"MLST"/utf8>>);
{nlst, P@5} ->
_pipe@6 = P@5,
_pipe@7 = gleam@option:map(
_pipe@6,
fun(X@3) -> <<"NLST "/utf8, X@3/binary>> end
),
gleam@option:unwrap(_pipe@7, <<"NLST"/utf8>>);
{opts, Command_name, Command_opts} ->
_pipe@8 = Command_opts,
_pipe@9 = gleam@option:map(
_pipe@8,
fun(Opts) ->
<<<<<<"OPTS "/utf8, Command_name/binary>>/binary, " "/utf8>>/binary,
Opts/binary>>
end
),
gleam@option:unwrap(_pipe@9, <<"OPTS "/utf8, Command_name/binary>>);
noop ->
<<"NOOP"/utf8>>;
{pass, P@6} ->
<<"PASS "/utf8, P@6/binary>>;
pasv ->
<<"PASV"/utf8>>;
{pbsz, Sz} ->
<<"PBSZ "/utf8, (erlang:integer_to_binary(Sz))/binary>>;
{port, P@7} ->
<<"PORT "/utf8, P@7/binary>>;
{prot, L} ->
<<"PROT "/utf8,
(gftp@internal@command@protection_level:to_string(L))/binary>>;
pwd ->
<<"PWD"/utf8>>;
quit ->
<<"QUIT"/utf8>>;
{rename_from, P@8} ->
<<"RNFR "/utf8, P@8/binary>>;
{rename_to, P@9} ->
<<"RNTO "/utf8, P@9/binary>>;
{rest, Offset} ->
<<"REST "/utf8, (erlang:integer_to_binary(Offset))/binary>>;
{retr, P@10} ->
<<"RETR "/utf8, P@10/binary>>;
{rmd, P@11} ->
<<"RMD "/utf8, P@11/binary>>;
{site, P@12} ->
<<"SITE "/utf8, P@12/binary>>;
{size, P@13} ->
<<"SIZE "/utf8, P@13/binary>>;
{stor, P@14} ->
<<"STOR "/utf8, P@14/binary>>;
{type, T} ->
<<"TYPE "/utf8, (gftp@file_type:to_string(T))/binary>>;
{user, U} ->
<<"USER "/utf8, U/binary>>;
{custom, C} ->
C
end.