2013-06-24 21:33:16 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2014-04-01 09:20:52 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2013-2014. All rights reserved. ;;
|
2013-06-24 21:33:16 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; ftpc.asm - FTP client for KolibriOS ;;
|
|
|
|
;; ;;
|
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
format binary as ""
|
|
|
|
|
2014-05-07 09:31:49 +02:00
|
|
|
TIMEOUT = 3 ; seconds
|
|
|
|
|
2013-07-10 11:37:01 +02:00
|
|
|
BUFFERSIZE = 4096
|
2013-06-24 21:33:16 +02:00
|
|
|
|
|
|
|
STATUS_CONNECTING = 0
|
|
|
|
STATUS_CONNECTED = 1
|
|
|
|
STATUS_NEEDPASSWORD = 2
|
|
|
|
STATUS_LOGGED_IN = 3
|
|
|
|
|
2013-07-13 10:50:07 +02:00
|
|
|
OPERATION_NONE = 0
|
|
|
|
OPERATION_LIST = 1
|
|
|
|
OPERATION_RETR = 2
|
|
|
|
OPERATION_STOR = 3
|
2014-05-12 01:42:10 +02:00
|
|
|
OPERATION_RDIR = 4
|
|
|
|
|
2013-06-24 21:33:16 +02:00
|
|
|
use32
|
|
|
|
; standard header
|
|
|
|
db 'MENUET01' ; signature
|
|
|
|
dd 1 ; header version
|
|
|
|
dd start ; entry point
|
|
|
|
dd i_end ; initialized size
|
|
|
|
dd mem+0x1000 ; required memory
|
|
|
|
dd mem+0x1000 ; stack pointer
|
2014-05-12 01:42:10 +02:00
|
|
|
dd buf_cmd ; parameters
|
2013-06-24 21:33:16 +02:00
|
|
|
dd 0 ; path
|
|
|
|
|
|
|
|
include '../../macros.inc'
|
|
|
|
purge mov,add,sub
|
|
|
|
include '../../proc32.inc'
|
|
|
|
include '../../dll.inc'
|
|
|
|
include '../../network.inc'
|
|
|
|
|
|
|
|
include 'usercommands.inc'
|
|
|
|
include 'servercommands.inc'
|
|
|
|
|
|
|
|
start:
|
2014-05-12 01:42:10 +02:00
|
|
|
; initialize heap for using dynamic blocks
|
|
|
|
mcall 68,11
|
|
|
|
test eax,eax
|
|
|
|
je exit2
|
|
|
|
|
2014-05-07 09:31:49 +02:00
|
|
|
; disable all events except network event
|
|
|
|
mcall 40, EV_STACK
|
2013-06-24 21:33:16 +02:00
|
|
|
; load libraries
|
|
|
|
stdcall dll.Load, @IMPORT
|
|
|
|
test eax, eax
|
|
|
|
jnz exit
|
|
|
|
; initialize console
|
2013-07-09 22:19:08 +02:00
|
|
|
invoke con_start, 1
|
2013-07-12 10:59:34 +02:00
|
|
|
invoke con_init, 80, 25, 80, 250, str_title
|
|
|
|
; Check for parameters, if there are some, resolve the address right away
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp byte [buf_cmd], 0
|
2013-06-24 21:33:16 +02:00
|
|
|
jne resolve
|
|
|
|
|
|
|
|
main:
|
2013-07-12 10:59:34 +02:00
|
|
|
; Clear screen
|
2013-07-09 22:19:08 +02:00
|
|
|
invoke con_cls
|
2013-06-24 21:33:16 +02:00
|
|
|
; Welcome user
|
2013-07-12 10:59:34 +02:00
|
|
|
invoke con_write_asciiz, str_welcome
|
|
|
|
; write prompt (in green color)
|
2013-07-09 22:19:08 +02:00
|
|
|
invoke con_set_flags, 0x0a
|
2013-07-12 10:59:34 +02:00
|
|
|
invoke con_write_asciiz, str_prompt
|
2013-06-24 21:33:16 +02:00
|
|
|
; read string
|
2014-05-12 01:42:10 +02:00
|
|
|
invoke con_gets, buf_cmd, 256
|
2013-06-24 21:33:16 +02:00
|
|
|
; check for exit
|
|
|
|
test eax, eax
|
|
|
|
jz done
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp byte [buf_cmd], 10
|
2013-06-24 21:33:16 +02:00
|
|
|
jz done
|
2013-07-12 10:59:34 +02:00
|
|
|
; reset color back to grey and print newline
|
|
|
|
invoke con_set_flags, 0x07
|
|
|
|
invoke con_write_asciiz, str_newline
|
2013-06-24 21:33:16 +02:00
|
|
|
|
|
|
|
resolve:
|
|
|
|
; delete terminating '\n'
|
2014-05-12 01:42:10 +02:00
|
|
|
mov esi, buf_cmd
|
2013-06-24 21:33:16 +02:00
|
|
|
@@:
|
|
|
|
lodsb
|
|
|
|
cmp al, 0x20
|
|
|
|
ja @r
|
|
|
|
mov byte [esi-1], 0
|
2013-07-12 10:59:34 +02:00
|
|
|
; Say to the user that we're resolving
|
|
|
|
invoke con_write_asciiz, str_resolve
|
2014-05-12 01:42:10 +02:00
|
|
|
invoke con_write_asciiz, buf_cmd
|
2013-06-24 21:33:16 +02:00
|
|
|
; resolve name
|
|
|
|
push esp ; reserve stack place
|
2014-05-12 01:42:10 +02:00
|
|
|
invoke getaddrinfo, buf_cmd, 0, 0, esp
|
2013-06-24 21:33:16 +02:00
|
|
|
pop esi
|
|
|
|
; test for error
|
|
|
|
test eax, eax
|
2013-07-12 10:59:34 +02:00
|
|
|
jnz error_resolve
|
2013-06-24 21:33:16 +02:00
|
|
|
; write results
|
2013-07-10 11:37:01 +02:00
|
|
|
invoke con_write_asciiz, str8 ; ' (',0
|
|
|
|
mov eax, [esi+addrinfo.ai_addr] ; convert IP address to decimal notation
|
|
|
|
mov eax, [eax+sockaddr_in.sin_addr] ;
|
|
|
|
mov [sockaddr1.ip], eax ;
|
|
|
|
invoke inet_ntoa, eax ;
|
|
|
|
invoke con_write_asciiz, eax ; print ip
|
|
|
|
invoke freeaddrinfo, esi ; free allocated memory
|
|
|
|
invoke con_write_asciiz, str9 ; ')',10,0
|
|
|
|
; open the socket
|
2013-06-24 21:33:16 +02:00
|
|
|
mcall socket, AF_INET4, SOCK_STREAM, 0
|
|
|
|
cmp eax, -1
|
2013-07-12 10:59:34 +02:00
|
|
|
je error_socket
|
2013-06-24 21:33:16 +02:00
|
|
|
mov [socketnum], eax
|
2013-07-10 11:37:01 +02:00
|
|
|
; connect to the server
|
2013-07-12 10:59:34 +02:00
|
|
|
invoke con_write_asciiz, str_connect
|
2013-06-24 21:33:16 +02:00
|
|
|
mcall connect, [socketnum], sockaddr1, 18
|
2014-05-07 09:31:49 +02:00
|
|
|
cmp eax, -1
|
|
|
|
je error_connect
|
2013-06-24 21:33:16 +02:00
|
|
|
mov [status], STATUS_CONNECTING
|
2013-07-12 10:59:34 +02:00
|
|
|
; Tell the user we're waiting for the server now.
|
|
|
|
invoke con_write_asciiz, str_waiting
|
2013-06-24 21:33:16 +02:00
|
|
|
|
2013-07-12 10:59:34 +02:00
|
|
|
; Reset 'offset' variable, it's used by the data receiver
|
2013-07-09 22:55:18 +02:00
|
|
|
mov [offset], 0
|
|
|
|
|
2013-07-09 22:19:08 +02:00
|
|
|
wait_for_servercommand:
|
2013-07-12 10:59:34 +02:00
|
|
|
; Any commands still in our buffer?
|
2013-07-09 22:55:18 +02:00
|
|
|
cmp [offset], 0
|
2013-07-12 10:59:34 +02:00
|
|
|
je .receive ; nope, receive some more
|
2013-07-09 22:55:18 +02:00
|
|
|
mov esi, [offset]
|
2014-05-12 01:42:10 +02:00
|
|
|
mov edi, buf_cmd
|
2013-07-09 22:55:18 +02:00
|
|
|
mov ecx, [size]
|
|
|
|
add ecx, esi
|
|
|
|
jmp .byteloop
|
2013-06-24 21:33:16 +02:00
|
|
|
|
|
|
|
; receive socket data
|
2013-07-09 22:55:18 +02:00
|
|
|
.receive:
|
2014-05-07 09:31:49 +02:00
|
|
|
mcall 26, 9
|
|
|
|
add eax, TIMEOUT*100
|
|
|
|
mov [timeout], eax
|
|
|
|
.receive_loop:
|
|
|
|
mcall 23, 50 ; Wait for event with timeout
|
|
|
|
mcall 26, 9
|
|
|
|
cmp eax, [timeout]
|
|
|
|
jge error_timeout
|
2014-05-12 01:42:10 +02:00
|
|
|
mcall recv, [socketnum], buf_buffer1, BUFFERSIZE, MSG_DONTWAIT
|
2014-05-07 09:31:49 +02:00
|
|
|
test eax, eax
|
|
|
|
jnz .got_data
|
|
|
|
cmp ebx, EWOULDBLOCK
|
|
|
|
jne error_socket
|
|
|
|
jmp .receive_loop
|
2013-07-09 22:19:08 +02:00
|
|
|
|
2014-05-07 09:31:49 +02:00
|
|
|
.got_data:
|
2013-07-09 22:55:18 +02:00
|
|
|
mov [offset], 0
|
2013-06-24 21:33:16 +02:00
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
; extract commands, copy them to "buf_cmd" buffer
|
|
|
|
lea ecx, [eax + buf_buffer1] ; ecx = end pointer
|
|
|
|
mov esi, buf_buffer1 ; esi = current pointer
|
|
|
|
mov edi, buf_cmd
|
2013-06-24 21:33:16 +02:00
|
|
|
.byteloop:
|
2013-07-09 22:19:08 +02:00
|
|
|
cmp esi, ecx
|
|
|
|
jae wait_for_servercommand
|
2013-06-24 21:33:16 +02:00
|
|
|
lodsb
|
|
|
|
cmp al, 10 ; excellent, we might have a command
|
|
|
|
je .got_command
|
2013-07-09 22:19:08 +02:00
|
|
|
cmp al, 13 ; just ignore this byte
|
2013-06-24 21:33:16 +02:00
|
|
|
je .byteloop
|
|
|
|
stosb
|
|
|
|
jmp .byteloop
|
2013-07-09 22:19:08 +02:00
|
|
|
.got_command: ; we have a newline check if its a command
|
2013-07-09 22:55:18 +02:00
|
|
|
cmp esi, ecx
|
|
|
|
je .no_more_data
|
|
|
|
mov [offset], esi
|
|
|
|
sub ecx, esi
|
|
|
|
mov [size], ecx
|
|
|
|
jmp .go_cmd
|
|
|
|
.no_more_data:
|
|
|
|
mov [offset], 0
|
|
|
|
.go_cmd:
|
2014-05-12 01:42:10 +02:00
|
|
|
lea ecx, [edi - buf_cmd] ; length of command
|
2013-06-24 21:33:16 +02:00
|
|
|
xor al, al
|
|
|
|
stosb
|
|
|
|
|
2013-07-09 22:19:08 +02:00
|
|
|
invoke con_set_flags, 0x03 ; change color
|
2014-05-12 01:42:10 +02:00
|
|
|
invoke con_write_asciiz, buf_cmd ; print servercommand
|
2013-07-12 10:59:34 +02:00
|
|
|
invoke con_write_asciiz, str_newline
|
2013-07-10 11:37:01 +02:00
|
|
|
invoke con_set_flags, 0x07 ; reset color
|
2013-06-24 21:33:16 +02:00
|
|
|
|
2013-07-09 22:19:08 +02:00
|
|
|
jmp server_parser ; parse command
|
2013-06-24 21:33:16 +02:00
|
|
|
|
2013-07-12 10:59:34 +02:00
|
|
|
|
|
|
|
|
2013-06-24 21:33:16 +02:00
|
|
|
wait_for_usercommand:
|
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
; Are there any files in the transfer queue?
|
|
|
|
|
|
|
|
cmp [queued], 0
|
|
|
|
ja transfer_queued ; Yes, transfer those first.
|
|
|
|
|
2013-07-12 10:59:34 +02:00
|
|
|
; change color to green for user input
|
2013-07-09 22:19:08 +02:00
|
|
|
invoke con_set_flags, 0x0a
|
|
|
|
|
2013-07-12 10:59:34 +02:00
|
|
|
; If we are not yet connected, request username/password
|
2013-06-24 21:33:16 +02:00
|
|
|
cmp [status], STATUS_CONNECTED
|
|
|
|
je .connected
|
|
|
|
|
|
|
|
cmp [status], STATUS_NEEDPASSWORD
|
|
|
|
je .needpass
|
|
|
|
|
|
|
|
; write prompt
|
2013-07-12 10:59:34 +02:00
|
|
|
invoke con_write_asciiz, str_prompt
|
2013-06-24 21:33:16 +02:00
|
|
|
; read string
|
2014-05-12 01:42:10 +02:00
|
|
|
invoke con_gets, buf_cmd, 256
|
2013-07-09 23:59:02 +02:00
|
|
|
|
2013-07-12 10:59:34 +02:00
|
|
|
; print a newline and reset the color back to grey
|
|
|
|
invoke con_write_asciiz, str_newline
|
2013-07-09 22:19:08 +02:00
|
|
|
invoke con_set_flags, 0x07
|
2013-06-24 21:33:16 +02:00
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp dword[buf_cmd], "cwd "
|
2013-07-09 22:55:18 +02:00
|
|
|
je cmd_cwd
|
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp dword[buf_cmd], "mkd "
|
2013-07-12 10:59:34 +02:00
|
|
|
je cmd_mkd
|
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp dword[buf_cmd], "rmd "
|
2013-07-12 10:59:34 +02:00
|
|
|
je cmd_rmd
|
2013-07-09 23:31:47 +02:00
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp dword[buf_cmd], "pwd" + 10 shl 24
|
2013-07-09 23:59:02 +02:00
|
|
|
je cmd_pwd
|
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp dword[buf_cmd], "bye" + 10 shl 24
|
2013-07-12 10:59:34 +02:00
|
|
|
je cmd_bye
|
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp dword[buf_cmd], "rdir"
|
|
|
|
je cmd_rdir
|
|
|
|
|
|
|
|
cmp byte[buf_cmd+4], " "
|
2013-07-12 10:59:34 +02:00
|
|
|
jne @f
|
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp dword[buf_cmd], "lcwd"
|
2013-07-12 10:59:34 +02:00
|
|
|
je cmd_lcwd
|
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp dword[buf_cmd], "retr"
|
2013-07-12 10:59:34 +02:00
|
|
|
je cmd_retr
|
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp dword[buf_cmd], "stor"
|
2013-07-10 11:37:01 +02:00
|
|
|
je cmd_stor
|
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp dword[buf_cmd], "dele"
|
2013-07-10 11:37:01 +02:00
|
|
|
je cmd_dele
|
|
|
|
|
2013-07-12 10:59:34 +02:00
|
|
|
@@:
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp byte[buf_cmd+4], 10
|
2013-07-12 10:59:34 +02:00
|
|
|
jne @f
|
2013-07-10 12:17:07 +02:00
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp dword[buf_cmd], "list"
|
2013-07-12 10:59:34 +02:00
|
|
|
je cmd_list
|
2013-07-10 13:19:18 +02:00
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp dword[buf_cmd], "help"
|
2013-07-12 10:59:34 +02:00
|
|
|
je cmd_help
|
2013-07-10 13:19:18 +02:00
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
cmp dword[buf_cmd], "cdup"
|
2013-07-10 13:19:18 +02:00
|
|
|
je cmd_cdup
|
|
|
|
|
2013-07-12 10:59:34 +02:00
|
|
|
@@:
|
|
|
|
; Uh oh.. unknown command, tell the user and wait for new input
|
2013-07-09 22:19:08 +02:00
|
|
|
invoke con_write_asciiz, str_unknown
|
2013-06-24 21:33:16 +02:00
|
|
|
jmp wait_for_usercommand
|
|
|
|
|
|
|
|
|
|
|
|
.connected:
|
2013-07-12 10:59:34 +02:00
|
|
|
; request username
|
2013-07-09 22:19:08 +02:00
|
|
|
invoke con_write_asciiz, str_user
|
2014-05-12 01:42:10 +02:00
|
|
|
mov dword[buf_cmd], "USER"
|
|
|
|
mov byte[buf_cmd+4], " "
|
2013-06-24 21:33:16 +02:00
|
|
|
jmp .send
|
|
|
|
|
|
|
|
|
|
|
|
.needpass:
|
2013-07-12 10:59:34 +02:00
|
|
|
; request password
|
2013-07-09 22:19:08 +02:00
|
|
|
invoke con_write_asciiz, str_pass
|
2014-05-12 01:42:10 +02:00
|
|
|
mov dword[buf_cmd], "PASS"
|
|
|
|
mov byte[buf_cmd+4], " "
|
2013-07-10 12:23:07 +02:00
|
|
|
invoke con_set_flags, 0x00 ; black text on black background for password
|
2013-06-24 21:33:16 +02:00
|
|
|
|
|
|
|
.send:
|
|
|
|
; read string
|
2014-05-12 01:42:10 +02:00
|
|
|
mov esi, buf_cmd+5
|
2013-07-09 22:19:08 +02:00
|
|
|
invoke con_gets, esi, 256
|
2013-06-24 21:33:16 +02:00
|
|
|
|
2013-07-10 11:37:01 +02:00
|
|
|
; find end of string
|
2014-05-12 01:42:10 +02:00
|
|
|
mov edi, buf_cmd+5
|
2013-06-24 21:33:16 +02:00
|
|
|
mov ecx, 256
|
|
|
|
xor al, al
|
|
|
|
repne scasb
|
2014-05-12 01:42:10 +02:00
|
|
|
lea esi, [edi-buf_cmd]
|
2013-07-12 11:58:26 +02:00
|
|
|
mov word[edi-2], 0x0a0d
|
2013-07-10 11:37:01 +02:00
|
|
|
; and send it to the server
|
2014-05-12 01:42:10 +02:00
|
|
|
mcall send, [socketnum], buf_cmd, , 0
|
2013-06-24 21:33:16 +02:00
|
|
|
|
2013-07-12 10:59:34 +02:00
|
|
|
invoke con_write_asciiz, str_newline
|
2013-07-10 11:37:01 +02:00
|
|
|
invoke con_set_flags, 0x07 ; reset color
|
2013-07-09 22:19:08 +02:00
|
|
|
jmp wait_for_servercommand
|
2013-06-24 21:33:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-10 11:37:01 +02:00
|
|
|
open_dataconnection: ; only passive for now..
|
2013-06-24 21:33:16 +02:00
|
|
|
cmp [status], STATUS_LOGGED_IN
|
|
|
|
jne .fail
|
|
|
|
|
2013-07-13 10:50:07 +02:00
|
|
|
mcall send, [socketnum], str_PASV, str_PASV.length, 0
|
2013-06-24 21:33:16 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.fail:
|
2013-07-12 22:35:53 +02:00
|
|
|
invoke con_get_flags
|
|
|
|
push eax
|
|
|
|
invoke con_set_flags, 0x0c ; print errors in red
|
2013-07-12 10:59:34 +02:00
|
|
|
invoke con_write_asciiz, str_err_socket
|
2013-07-12 22:35:53 +02:00
|
|
|
invoke con_set_flags ; reset color
|
2013-06-24 21:33:16 +02:00
|
|
|
ret
|
|
|
|
|
2014-05-07 09:31:49 +02:00
|
|
|
error_connect:
|
|
|
|
invoke con_set_flags, 0x0c ; print errors in red
|
|
|
|
invoke con_write_asciiz, str_err_connect
|
|
|
|
jmp wait_for_keypress
|
2013-06-24 21:33:16 +02:00
|
|
|
|
2014-05-07 09:31:49 +02:00
|
|
|
error_timeout:
|
|
|
|
invoke con_set_flags, 0x0c ; print errors in red
|
|
|
|
invoke con_write_asciiz, str_err_timeout
|
|
|
|
jmp wait_for_keypress
|
2013-06-24 21:33:16 +02:00
|
|
|
|
2013-07-12 10:59:34 +02:00
|
|
|
error_socket:
|
2013-07-12 22:35:53 +02:00
|
|
|
invoke con_set_flags, 0x0c ; print errors in red
|
2013-07-12 10:59:34 +02:00
|
|
|
invoke con_write_asciiz, str_err_socket
|
|
|
|
jmp wait_for_keypress
|
|
|
|
|
|
|
|
error_resolve:
|
2013-07-12 22:35:53 +02:00
|
|
|
invoke con_set_flags, 0x0c ; print errors in red
|
2013-07-12 10:59:34 +02:00
|
|
|
invoke con_write_asciiz, str_err_resolve
|
2013-06-24 21:33:16 +02:00
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
error_heap:
|
|
|
|
invoke con_set_flags, 0x0c ; print errors in red
|
|
|
|
invoke con_write_asciiz, str_err_heap
|
|
|
|
|
2013-07-12 10:59:34 +02:00
|
|
|
wait_for_keypress:
|
2013-07-12 22:35:53 +02:00
|
|
|
invoke con_set_flags, 0x07 ; reset color to grey
|
2013-07-12 10:59:34 +02:00
|
|
|
invoke con_write_asciiz, str_push
|
2013-07-09 22:19:08 +02:00
|
|
|
invoke con_getch2
|
2013-07-12 22:35:53 +02:00
|
|
|
mcall close, [socketnum]
|
2013-06-24 21:33:16 +02:00
|
|
|
jmp main
|
|
|
|
|
|
|
|
done:
|
2013-07-09 22:19:08 +02:00
|
|
|
invoke con_exit, 1
|
2013-06-24 21:33:16 +02:00
|
|
|
|
2013-07-09 22:19:08 +02:00
|
|
|
exit:
|
2013-06-24 21:33:16 +02:00
|
|
|
mcall close, [socketnum]
|
2014-05-12 01:42:10 +02:00
|
|
|
exit2:
|
2013-06-24 21:33:16 +02:00
|
|
|
mcall -1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; data
|
2013-07-12 10:59:34 +02:00
|
|
|
str_title db 'FTP client',0
|
2014-05-07 09:31:49 +02:00
|
|
|
str_welcome db 'FTP client for KolibriOS v0.12',10
|
2013-07-12 10:59:34 +02:00
|
|
|
db 10
|
|
|
|
db 'Please enter ftp server address.',10,0
|
|
|
|
|
|
|
|
str_prompt db '> ',0
|
|
|
|
str_resolve db 'Resolving ',0
|
|
|
|
str_newline db 10,0
|
|
|
|
str_err_resolve db 10,'Name resolution failed.',10,0
|
|
|
|
str_err_socket db 10,'Socket error.',10,0
|
2014-05-12 01:42:10 +02:00
|
|
|
str_err_heap db 10,'Cannot allocate memory from heap.',10,0
|
2014-05-07 09:31:49 +02:00
|
|
|
str_err_timeout db 10,'Timeout - no response from server.',10,0
|
|
|
|
str_err_connect db 10,'Cannot connect to the server.',10,0
|
2013-07-12 10:59:34 +02:00
|
|
|
str8 db ' (',0
|
|
|
|
str9 db ')',10,0
|
|
|
|
str_push db 'Push any key to continue.',0
|
|
|
|
str_connect db 'Connecting...',10,0
|
|
|
|
str_waiting db 'Waiting for welcome message.',10,0
|
|
|
|
str_user db "username: ",0
|
|
|
|
str_pass db "password: ",0
|
|
|
|
str_unknown db "Unknown command or insufficient parameters - type help for more information.",10,0
|
|
|
|
str_lcwd db "Local working directory is now: ",0
|
|
|
|
|
|
|
|
str_open db "opening data socket",10,0
|
2014-05-12 01:42:10 +02:00
|
|
|
str_close db 10,"closing data socket",10,0
|
|
|
|
str_dot db '.',0
|
2013-07-12 10:59:34 +02:00
|
|
|
|
|
|
|
str_help db "available commands:",10
|
|
|
|
db 10
|
|
|
|
db "bye - close the connection",10
|
|
|
|
db "cdup - change to parent of current directory on the server",10
|
|
|
|
db "cwd <directory> - change working directoy on the server",10
|
|
|
|
db "dele <file> - delete file from the server",10
|
|
|
|
db "list - list files and folders in current server directory",10
|
|
|
|
db "lcwd <path> - change local working directory",10
|
|
|
|
db "mkd <directory> - make directory on the server",10
|
|
|
|
db "pwd - print server working directory",10
|
|
|
|
db "retr <file> - retreive file from the server",10
|
|
|
|
db "rmd <directory> - remove directory from the server",10
|
|
|
|
db "stor <file> - store file on the server",10
|
2014-05-12 01:42:10 +02:00
|
|
|
db "rdir - retreive all files from current server dir",10
|
2013-07-12 10:59:34 +02:00
|
|
|
db 10,0
|
2013-06-24 21:33:16 +02:00
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
queued dd 0
|
2013-07-13 10:50:07 +02:00
|
|
|
|
|
|
|
; FTP strings
|
|
|
|
|
|
|
|
str_PASV db 'PASV',13,10
|
|
|
|
.length = $ - str_PASV
|
|
|
|
|
2013-06-24 21:33:16 +02:00
|
|
|
sockaddr1:
|
|
|
|
dw AF_INET4
|
|
|
|
.port dw 0x1500 ; 21
|
|
|
|
.ip dd 0
|
|
|
|
rb 10
|
|
|
|
|
|
|
|
sockaddr2:
|
|
|
|
dw AF_INET4
|
|
|
|
.port dw 0
|
|
|
|
.ip dd 0
|
|
|
|
rb 10
|
|
|
|
|
|
|
|
; import
|
|
|
|
align 4
|
|
|
|
@IMPORT:
|
|
|
|
|
|
|
|
library network, 'network.obj', console, 'console.obj'
|
|
|
|
|
|
|
|
import network, \
|
|
|
|
getaddrinfo, 'getaddrinfo', \
|
|
|
|
freeaddrinfo, 'freeaddrinfo', \
|
|
|
|
inet_ntoa, 'inet_ntoa'
|
|
|
|
|
|
|
|
import console, \
|
|
|
|
con_start, 'START', \
|
|
|
|
con_init, 'con_init', \
|
|
|
|
con_write_asciiz,'con_write_asciiz', \
|
|
|
|
con_exit, 'con_exit', \
|
|
|
|
con_gets, 'con_gets',\
|
|
|
|
con_cls, 'con_cls',\
|
|
|
|
con_getch2, 'con_getch2',\
|
|
|
|
con_set_cursor_pos, 'con_set_cursor_pos',\
|
|
|
|
con_write_string, 'con_write_string',\
|
2013-07-09 22:19:08 +02:00
|
|
|
con_get_flags, 'con_get_flags', \
|
|
|
|
con_set_flags, 'con_set_flags'
|
2013-06-24 21:33:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
i_end:
|
|
|
|
|
2013-07-12 10:59:34 +02:00
|
|
|
; uninitialised data
|
|
|
|
|
2013-07-09 23:59:02 +02:00
|
|
|
status db ?
|
2013-06-24 21:33:16 +02:00
|
|
|
active_passive db ?
|
2013-07-09 23:59:02 +02:00
|
|
|
|
2013-06-24 21:33:16 +02:00
|
|
|
socketnum dd ?
|
|
|
|
datasocket dd ?
|
2013-07-09 22:55:18 +02:00
|
|
|
offset dd ?
|
|
|
|
size dd ?
|
2013-07-10 11:37:01 +02:00
|
|
|
operation dd ?
|
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
size_fname dd ?
|
|
|
|
ptr_queue dd ?
|
2014-05-07 09:31:49 +02:00
|
|
|
timeout dd ?
|
2014-05-12 01:42:10 +02:00
|
|
|
ptr_fname_start dd ?
|
2014-05-07 09:31:49 +02:00
|
|
|
|
2013-07-10 11:37:01 +02:00
|
|
|
filestruct:
|
|
|
|
.subfn dd ?
|
|
|
|
.offset dd ?
|
|
|
|
dd ?
|
|
|
|
.size dd ?
|
|
|
|
.ptr dd ?
|
|
|
|
.name rb 1024
|
2013-06-24 21:33:16 +02:00
|
|
|
|
2014-05-12 01:42:10 +02:00
|
|
|
buf_buffer1 rb BUFFERSIZE+1
|
|
|
|
buf_buffer2 rb BUFFERSIZE+1
|
|
|
|
buf_cmd rb 1024 ; buffer for holding command string
|
2013-06-24 21:33:16 +02:00
|
|
|
|
|
|
|
mem:
|