diff --git a/calexium_lib/net_services_protocols/ftp.anubis b/calexium_lib/net_services_protocols/ftp.anubis deleted file mode 100644 index 168e63e..0000000 --- a/calexium_lib/net_services_protocols/ftp.anubis +++ /dev/null @@ -1,151 +0,0 @@ -/* - * - * User: David RENE - * Date: 11/05/2007 - * Time: 22:34 - * (c) Calexium - * - * To change this template use Tools | Options | Coding | Edit Standard Headers. - */ - -read calexium_lib/CXM_message_constants.anubis -read calexium_lib/net_services/CXM_generic_protocol.anubis -read system/message_queue.anubis -read system/message_transceiver.anubis -read system/muscle.anubis -read tools/basis.anubis - -define One - receive_data - ( - MessageQueue mQ, - WStream fd, - Int32 so_far, - Int32 left_read - )= - //println("receive_data "); - if mQ.get_next_received_Message(30) is - { - timeout then unique, - closed then unique, - 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), - success(data) then - if write(fd, data) is - { - failure then println("Can't write into file"); send_ACK_error(mQ, _CXM_FTP_DATA), - success(len) then - send_ACK_ok(mQ, _CXM_FTP_DATA); - if last_block then - println("File received successfully"); - unique - else - println("Bytes received : " + (so_far + len)); - receive_data(mQ, fd, so_far + len, left_read - len) - } - } - } - . - -define One - start_get_file_transtert - ( - MessageQueue mQ, - String local_file, - Int32 size - )= - if file(local_file, new) is - { - failure then println("Can't create \""+local_file+"\" file"), - success(fd) then //the local file is open - with start = message(_CXM_FTP_START_TRANSFERT), - mQ.add_Message_to_send(start); - receive_data(mQ, weaken(fd), 0, size) - } - . - -define One - get_file - ( - MessageQueue mQ, - String remote_file, - String local_file - )= - with get_file_msg = message(_CXM_FTP_GET_FILE), - if add_string(get_file_msg, "FileName", remote_file) is - { - failure then unique, - 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, - ok_msg(msg)then - if find_int32(msg, "FileSize") is - { - failure then println("file size not found"); unique, - success(size) then - start_get_file_transtert(mQ, local_file, size) - } - } - } - . - - -define Bool - request_for_service - ( - MessageQueue queue - )= - with test_msg = message(_CXM_REQUEST_FOR_SERVICE), - forget(add_int32(test_msg, "service", _CXM_FTP_SERVICE_ID)); - forget(add_int32(test_msg, "version", 1)); - queue.add_Message_to_send(test_msg); - if queue.get_next_received_Message(30) is - { - timeout then println("request_for_service receive timeout");false, - closed then println("request_for_service socket closed");false, - msg(msg) then - if find_int32(msg, "STATUS") is - { - failure then println("status not found");false, - success(v) then - if v = _CXM_OK then - true - else - false - } - }. - -public define One - ftp_get_file - ( - String server, - Int32 ip_port, - String remote_file, - String local_file - )= - if dns(server) is ok(ip_adr) then - if connect( ip_adr, ip_port) is - { - error(_) then println("can't connect to ftp server"), - 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") - } - else - println("server "+server+" DNS error") - . - diff --git a/calexium_lib/net_services_protocols/ftp_client.anubis b/calexium_lib/net_services_protocols/ftp_client.anubis new file mode 100644 index 0000000..168e63e --- /dev/null +++ b/calexium_lib/net_services_protocols/ftp_client.anubis @@ -0,0 +1,151 @@ +/* + * + * User: David RENE + * Date: 11/05/2007 + * Time: 22:34 + * (c) Calexium + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ + +read calexium_lib/CXM_message_constants.anubis +read calexium_lib/net_services/CXM_generic_protocol.anubis +read system/message_queue.anubis +read system/message_transceiver.anubis +read system/muscle.anubis +read tools/basis.anubis + +define One + receive_data + ( + MessageQueue mQ, + WStream fd, + Int32 so_far, + Int32 left_read + )= + //println("receive_data "); + if mQ.get_next_received_Message(30) is + { + timeout then unique, + closed then unique, + 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), + success(data) then + if write(fd, data) is + { + failure then println("Can't write into file"); send_ACK_error(mQ, _CXM_FTP_DATA), + success(len) then + send_ACK_ok(mQ, _CXM_FTP_DATA); + if last_block then + println("File received successfully"); + unique + else + println("Bytes received : " + (so_far + len)); + receive_data(mQ, fd, so_far + len, left_read - len) + } + } + } + . + +define One + start_get_file_transtert + ( + MessageQueue mQ, + String local_file, + Int32 size + )= + if file(local_file, new) is + { + failure then println("Can't create \""+local_file+"\" file"), + success(fd) then //the local file is open + with start = message(_CXM_FTP_START_TRANSFERT), + mQ.add_Message_to_send(start); + receive_data(mQ, weaken(fd), 0, size) + } + . + +define One + get_file + ( + MessageQueue mQ, + String remote_file, + String local_file + )= + with get_file_msg = message(_CXM_FTP_GET_FILE), + if add_string(get_file_msg, "FileName", remote_file) is + { + failure then unique, + 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, + ok_msg(msg)then + if find_int32(msg, "FileSize") is + { + failure then println("file size not found"); unique, + success(size) then + start_get_file_transtert(mQ, local_file, size) + } + } + } + . + + +define Bool + request_for_service + ( + MessageQueue queue + )= + with test_msg = message(_CXM_REQUEST_FOR_SERVICE), + forget(add_int32(test_msg, "service", _CXM_FTP_SERVICE_ID)); + forget(add_int32(test_msg, "version", 1)); + queue.add_Message_to_send(test_msg); + if queue.get_next_received_Message(30) is + { + timeout then println("request_for_service receive timeout");false, + closed then println("request_for_service socket closed");false, + msg(msg) then + if find_int32(msg, "STATUS") is + { + failure then println("status not found");false, + success(v) then + if v = _CXM_OK then + true + else + false + } + }. + +public define One + ftp_get_file + ( + String server, + Int32 ip_port, + String remote_file, + String local_file + )= + if dns(server) is ok(ip_adr) then + if connect( ip_adr, ip_port) is + { + error(_) then println("can't connect to ftp server"), + 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") + } + else + println("server "+server+" DNS error") + . + -- libgit2 0.21.4