Status: Experimental
Example unit test
- configure an ftp server | tested with a phone ftp app
- modify the ftp.environment.example and save as your file name to source
- source the modified environment file
- run the tests
. ftp.environment
go test
TODO:
- Log in. -- Done
- Download a file. -- Done
- Upload a file to an existing directory. -- Done
- List contents of remote directory.
- Create a new directory.
- Delete a a directory or a file.
FTP Protocol Command Summary
- To Download a file:
-
Log in
USER username
PASS password
-
Set the TYPE
TYPE I (binary) for binary files or TYPE A (ascii) for text files
Sample Response: 200 Type set to A or I
-
Set Passive transfer mode
PASV
Computing the destination port from the actual respone (127,0,0,1,201,208)
The first four octets are the IP address while the last two octets comprise the port that will be used for the data connection. To find the actual port multiply the fifth octet by 256 and then add the sixth octet to the total
Sample Response: 227 Entering Passive Mode (127,0,0,1,201,208)
-
Retrieve the file
RETR [file]
After you call RETR the data port will open and be available to download the file.
RETR doesn't return immediately, but waits until you open a connection to the
data port and download the file.
Sample Response: 150 opening connection
-
Open connection to data port
Read data bytes to a file
Sample Response: 226 Transfer complete
-
Close data port
-
Close the connection (optional, if you want to download multiple files in
one session)
QUIT
Sample Protocol Session (control session only):
$ telnet localhost 21
220 ProFTPD 1.3.2c Server (ProFTPD Test Server) [127.0.0.1]
USER
500 USER: command requires a parameter
USER anonymous
331 Anonymous login ok, send your complete email address as your password
PASS foo
230 Anonymous access granted, restrictions apply
TYPE I
200 Type set to I
PASV
227 Entering Passive Mode (127,0,0,1,201,208).
RETR test_file.txt
150 Opening BINARY mode data connection for test_file.txt (12 bytes)
226 Transfer complete
QUIT
221 Goodbye.