diff --git a/core/kazoo_attachments/src/kz_att_ftp.erl b/core/kazoo_attachments/src/kz_att_ftp.erl index d0eab4ff24b..1ba05346ddd 100644 --- a/core/kazoo_attachments/src/kz_att_ftp.erl +++ b/core/kazoo_attachments/src/kz_att_ftp.erl @@ -82,14 +82,14 @@ fetch_attachment(HandlerProps, DbName, DocId, AName) -> 'ok' | {'error', binary(), binary() | atom() | term()}. send_request(Url, Contents) -> case http_uri:parse(kz_term:to_list(Url)) of - {'ok',{'ftp', UserPass, Host, Port, FullPath,_Query}} -> - send_request(Host, Port, UserPass, FullPath, Contents); + {'ok',{Scheme, UserPass, Host, Port, FullPath,_Query}} -> + send_request(Scheme, Host, Port, UserPass, FullPath, Contents); _ -> {'error', <<"error parsing url: ", Url/binary>>} end. --spec send_request(string(), integer(), string(), string(), binary()) -> +-spec send_request(string(), string(), integer(), string(), string(), binary()) -> 'ok' | {'error', binary() | atom() | term()}. -send_request(Host, Port, UserPass, FullPath, Contents) -> +send_request(Scheme, Host, Port, UserPass, FullPath, Contents) -> {User, Pass} = case string:tokens(UserPass, ":") of [U, P] -> {U, P}; _ -> ftp_anonymous_user_pass() @@ -97,8 +97,7 @@ send_request(Host, Port, UserPass, FullPath, Contents) -> Dir = filename:dirname(FullPath), File = filename:basename(FullPath), try - Options = [{'port', Port}], - case ftp:open(Host, Options) of + case ftp:open(Host, get_options(Scheme, Port)) of {'ok', Pid} -> Routines = [fun() -> ftp:user(Pid, User, Pass) end ,fun() -> ftp:type(Pid, 'binary') end @@ -119,6 +118,13 @@ send_request(Host, Port, UserPass, FullPath, Contents) -> {'error', Err} end. +get_options('ftp', Port) -> + [{'port', Port}]; +get_options('ftps', Port) -> + [{'port', Port} + ,{'tls', []} + ]. + -spec ftp_cmds(list()) -> 'ok' | {'error', any()}. ftp_cmds([]) -> 'ok'; ftp_cmds([Fun|Funs]) -> diff --git a/core/kazoo_schemas/src/kz_json_schema_extensions.erl b/core/kazoo_schemas/src/kz_json_schema_extensions.erl index 825c3bede85..7412d4d5fef 100644 --- a/core/kazoo_schemas/src/kz_json_schema_extensions.erl +++ b/core/kazoo_schemas/src/kz_json_schema_extensions.erl @@ -239,13 +239,22 @@ is_valid_scheme(<<"http">>) -> 'true'; is_valid_scheme(<<"https">>) -> 'true'; is_valid_scheme(_) -> 'false'. -is_valid_ftp_url({'ok',{'ftp', _UserPass, Host, _Port, _FullPath,_Query}}) -> +is_valid_ftp_url({'ok',{'ftp', _UserPass, Host, _Port, _FullPath, _Query}}) -> is_valid_host(kz_term:to_binary(Host)); +is_valid_ftp_url({'ok',{'ftps', UserPass, Host, _Port, _FullPath, _Query}}) -> + lists:all(fun is_valid_url_part/1 + ,[{fun is_valid_ftp_userpass/1, string:tokens(UserPass, ":")} + ,{fun is_valid_host/1, kz_term:to_binary(Host)} + ] + ); is_valid_ftp_url(<>) -> is_valid_ftp_url(http_uri:parse(kz_term:to_list(URL))); is_valid_ftp_url(_URL) -> 'false'. +is_valid_ftp_userpass([_User, _Pass]) -> 'true'; +is_valid_ftp_userpass(_) -> 'false'. + -spec is_valid_host(kz_http_util:location()) -> boolean(). is_valid_host(<>) -> is_valid_host(kz_term:to_lower_binary(Host), kz_network_utils:is_ip(Host));