From 03f679013033b5da64d2de9d8c3d7aa01030e059 Mon Sep 17 00:00:00 2001 From: David RENE Date: Mon, 2 Jul 2012 10:16:30 +0000 Subject: [PATCH] add the management of FTP_DIR into ftp protocol Add get_ip as public for resolving ip or URL --- calexium_lib/net_services/CXM_generic_client.anubis | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ calexium_lib/net_services_protocols/ftp_client.anubis | 32 ++++++++++++++++++++++++++++---- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/calexium_lib/net_services/CXM_generic_client.anubis b/calexium_lib/net_services/CXM_generic_client.anubis index 7025050..ee16108 100644 --- a/calexium_lib/net_services/CXM_generic_client.anubis +++ b/calexium_lib/net_services/CXM_generic_client.anubis @@ -196,7 +196,59 @@ public define Maybe($T) queue.quit(unique); result }. + +define Word32 + get_ip + ( + String url_or_ip, + (String) -> One logger + ) = + //logInfo(debug_log,"Try to resolve URL [" + url_or_ip+ "]."); + if ip_address(url_or_ip) is success(ip) then + //logInfo(debug_log,"Try to resolve URL OK ip"+ip); + ip + else if dns(url_or_ip) is ok(ip_adr) then + //logInfo(debug_log,"Try to resolve URL OK dns"+ip_adr); + ip_adr + else + logger("Can't resolve URL [" + url_or_ip+ "]. Using localhost."); + ip_address((127,0,0,1)). + +public define Maybe(Word32) + get_ip + ( + String url_or_ip + ) = + //logInfo(debug_log,"Try to resolve URL [" + url_or_ip+ "]."); + if ip_address(url_or_ip) is success(ip) then + //logInfo(debug_log,"Try to resolve URL OK ip"+ip); + success(ip) + else if dns(url_or_ip) is ok(ip_adr) then + //logInfo(debug_log,"Try to resolve URL OK dns"+ip_adr); + success(ip_adr) + else + println("Can't resolve URL [" + url_or_ip+ "]. Using localhost."); + failure. + + /* Same version as above, but server is string containing IP or URL + * It's resolve by get_ip and call generic_connect_to_net_service with IP + */ + +public define Maybe($T) + generic_connect_to_net_service + ( + String queue_name, + String server, + Word32 port, + Word32 service_id, + Word32 service_version, + (MessageQueue, String) -> Maybe($T) handler, + (String) -> One logger + ) + = generic_connect_to_net_service(queue_name, get_ip(server, logger), port, service_id, service_version, handler, logger). + + public define Maybe($T) generic_connect_to_net_service_SSL ( diff --git a/calexium_lib/net_services_protocols/ftp_client.anubis b/calexium_lib/net_services_protocols/ftp_client.anubis index e448420..c30d964 100644 --- a/calexium_lib/net_services_protocols/ftp_client.anubis +++ b/calexium_lib/net_services_protocols/ftp_client.anubis @@ -10,6 +10,7 @@ read calexium_lib/CXM_message_constants.anubis read calexium_lib/net_services/CXM_generic_protocol.anubis +read calexium_lib/net_services/CXM_generic_client.anubis //for get_ip read system/message_queue.anubis read system/message_transceiver.anubis read system/muscle.anubis @@ -77,13 +78,20 @@ define Maybe(One) ( MessageQueue mQ, String remote_file, - String local_file + String local_file, + Bool ftp )= with get_file_msg = message(_CXM_FTP_GET_FILE), if add_string(get_file_msg, "FileName", remote_file) is { failure then failure, success(_) then + ( if ftp then + println("get_file FTP_DIR"); + forget(add_bool(get_file_msg, "FTP_DIR", true)) + else + unique + ); mQ.add_Message_to_send(get_file_msg); if wait_for_reply(mQ, _CXM_FTP_GET_FILE, 30) is { @@ -135,17 +143,19 @@ public define Maybe(One) String server, Word32 ip_port, String remote_file, - String local_file + String local_file, + Bool ftp, ) = - if resolve_address(server) is success(ip_adr) then + if get_ip(server) is success(ip_adr) then if connect( ip_adr, ip_port) is { error(_) then println("can't connect to ftp server"); failure, ok(conn) then with queue = create_MessageQueue("ftp_get_file"), message_transceiver(conn, queue); + println("request for ftp service"); if request_for_service(queue) then - with result = get_file(queue, remote_file, local_file), + with result = get_file(queue, remote_file, local_file, ftp), queue.quit(unique);result else queue.quit(unique); @@ -154,4 +164,18 @@ public define Maybe(One) else println("server "+server+" DNS error");failure . + + /* Exists for backward compatibility. + * The last argument set to false (no ftp directory on the remote, pickup on collection dir) + */ +public define Maybe(One) + ftp_get_file + ( + String server, + Word32 ip_port, + String remote_file, + String local_file, + ) = + ftp_get_file(server, ip_port, remote_file, local_file, false). + -- libgit2 0.21.4