diff --git a/calexium_lib/net_services_protocols/ftp_client.anubis b/calexium_lib/net_services_protocols/ftp_client.anubis index 168e63e..91e1667 100644 --- a/calexium_lib/net_services_protocols/ftp_client.anubis +++ b/calexium_lib/net_services_protocols/ftp_client.anubis @@ -13,9 +13,10 @@ read calexium_lib/net_services/CXM_generic_protocol.anubis read system/message_queue.anubis read system/message_transceiver.anubis read system/muscle.anubis +read system/files.anubis read tools/basis.anubis -define One +define Maybe(One) receive_data ( MessageQueue mQ, @@ -26,22 +27,22 @@ define One //println("receive_data "); if mQ.get_next_received_Message(30) is { - timeout then unique, - closed then unique, + timeout then failure, + closed then failure, msg(_msg) then with last_block = if find_bool(_msg, "End") is {failure then false, success(r) then r}, if find_raw(_msg, "Data") is { - failure then println("Can't find raw Data"); send_ACK_error(mQ, _CXM_FTP_DATA), + failure then println("Can't find raw Data"); send_ACK_error(mQ, _CXM_FTP_DATA); failure, success(data) then if write(fd, data) is { - failure then println("Can't write into file"); send_ACK_error(mQ, _CXM_FTP_DATA), + failure then println("Can't write into file"); send_ACK_error(mQ, _CXM_FTP_DATA);failure, success(len) then send_ACK_ok(mQ, _CXM_FTP_DATA); if last_block then println("File received successfully"); - unique + success(unique) else println("Bytes received : " + (so_far + len)); receive_data(mQ, fd, so_far + len, left_read - len) @@ -50,16 +51,17 @@ define One } . -define One +define Maybe(One) start_get_file_transtert ( MessageQueue mQ, String local_file, Int32 size )= + make_directories(local_file); if file(local_file, new) is { - failure then println("Can't create \""+local_file+"\" file"), + failure then println("Can't create \""+local_file+"\" file"); failure, success(fd) then //the local file is open with start = message(_CXM_FTP_START_TRANSFERT), mQ.add_Message_to_send(start); @@ -67,7 +69,7 @@ define One } . -define One +define Maybe(One) get_file ( MessageQueue mQ, @@ -77,27 +79,26 @@ define One with get_file_msg = message(_CXM_FTP_GET_FILE), if add_string(get_file_msg, "FileName", remote_file) is { - failure then unique, + failure then failure, success(_) then mQ.add_Message_to_send(get_file_msg); println("_CXM_FTP_GET_FILE sent"); if wait_for_reply(mQ, _CXM_FTP_GET_FILE, 30) is { - failure then unique, - timeout then unique, - unknow_cmd then unique, - error then unique, - ok then unique, + failure then failure, + timeout then failure, + unknow_cmd then failure, + error then failure, + ok then failure, ok_msg(msg)then if find_int32(msg, "FileSize") is { - failure then println("file size not found"); unique, + failure then println("file size not found"); failure, success(size) then start_get_file_transtert(mQ, local_file, size) } } - } - . + }. define Bool @@ -125,7 +126,7 @@ define Bool } }. -public define One +public define Maybe(One) ftp_get_file ( String server, @@ -136,16 +137,16 @@ public define One if dns(server) is ok(ip_adr) then if connect( ip_adr, ip_port) is { - error(_) then println("can't connect to ftp server"), + error(_) then println("can't connect to ftp server"); failure, ok(conn) then with queue = create_MessageQueue, message_transceiver(conn, queue); if request_for_service(queue) then get_file(queue, remote_file, local_file) else - println("Service not found") + println("Service not found");failure } else - println("server "+server+" DNS error") + println("server "+server+" DNS error");failure . -- libgit2 0.21.4