investtools-ftpd 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +5 -0
  3. data/.yardopts +7 -0
  4. data/Changelog.md +310 -0
  5. data/Gemfile +15 -0
  6. data/Gemfile.lock +93 -0
  7. data/LICENSE.md +9 -0
  8. data/README.md +371 -0
  9. data/Rakefile +14 -0
  10. data/VERSION +1 -0
  11. data/doc/benchmarks.md +82 -0
  12. data/doc/references.md +66 -0
  13. data/doc/rfc-compliance.md +292 -0
  14. data/examples/example.rb +275 -0
  15. data/examples/example_spec.rb +93 -0
  16. data/examples/hello_world.rb +32 -0
  17. data/features/example/eplf.feature +14 -0
  18. data/features/example/example.feature +18 -0
  19. data/features/example/read_only.feature +63 -0
  20. data/features/example/step_definitions/example_server.rb +11 -0
  21. data/features/ftp_server/abort.feature +13 -0
  22. data/features/ftp_server/allo.feature +33 -0
  23. data/features/ftp_server/append.feature +94 -0
  24. data/features/ftp_server/cdup.feature +36 -0
  25. data/features/ftp_server/command_errors.feature +13 -0
  26. data/features/ftp_server/concurrent_sessions.feature +14 -0
  27. data/features/ftp_server/delay_after_failed_login.feature +23 -0
  28. data/features/ftp_server/delete.feature +60 -0
  29. data/features/ftp_server/directory_navigation.feature +59 -0
  30. data/features/ftp_server/disconnect_after_failed_logins.feature +25 -0
  31. data/features/ftp_server/eprt.feature +55 -0
  32. data/features/ftp_server/epsv.feature +36 -0
  33. data/features/ftp_server/features.feature +38 -0
  34. data/features/ftp_server/file_structure.feature +43 -0
  35. data/features/ftp_server/get.feature +80 -0
  36. data/features/ftp_server/get_ipv6.feature +43 -0
  37. data/features/ftp_server/get_tls.feature +23 -0
  38. data/features/ftp_server/help.feature +21 -0
  39. data/features/ftp_server/implicit_tls.feature +23 -0
  40. data/features/ftp_server/invertability.feature +15 -0
  41. data/features/ftp_server/list.feature +94 -0
  42. data/features/ftp_server/list_tls.feature +29 -0
  43. data/features/ftp_server/logging.feature +11 -0
  44. data/features/ftp_server/login_auth_level_account.feature +51 -0
  45. data/features/ftp_server/login_auth_level_password.feature +59 -0
  46. data/features/ftp_server/login_auth_level_user.feature +31 -0
  47. data/features/ftp_server/max_connections.feature +39 -0
  48. data/features/ftp_server/mdtm.feature +53 -0
  49. data/features/ftp_server/mkdir.feature +70 -0
  50. data/features/ftp_server/mode.feature +43 -0
  51. data/features/ftp_server/name_list.feature +77 -0
  52. data/features/ftp_server/name_list_tls.feature +30 -0
  53. data/features/ftp_server/noop.feature +17 -0
  54. data/features/ftp_server/options.feature +17 -0
  55. data/features/ftp_server/pasv.feature +23 -0
  56. data/features/ftp_server/port.feature +49 -0
  57. data/features/ftp_server/put.feature +79 -0
  58. data/features/ftp_server/put_tls.feature +23 -0
  59. data/features/ftp_server/put_unique.feature +56 -0
  60. data/features/ftp_server/quit.feature +23 -0
  61. data/features/ftp_server/reinitialize.feature +13 -0
  62. data/features/ftp_server/rename.feature +97 -0
  63. data/features/ftp_server/rmdir.feature +71 -0
  64. data/features/ftp_server/site.feature +13 -0
  65. data/features/ftp_server/size.feature +69 -0
  66. data/features/ftp_server/status.feature +18 -0
  67. data/features/ftp_server/step_definitions/logging.rb +8 -0
  68. data/features/ftp_server/step_definitions/test_server.rb +65 -0
  69. data/features/ftp_server/structure_mount.feature +13 -0
  70. data/features/ftp_server/syntax_errors.feature +18 -0
  71. data/features/ftp_server/syst.feature +18 -0
  72. data/features/ftp_server/timeout.feature +26 -0
  73. data/features/ftp_server/type.feature +59 -0
  74. data/features/step_definitions/append.rb +15 -0
  75. data/features/step_definitions/client.rb +24 -0
  76. data/features/step_definitions/client_and_server_files.rb +24 -0
  77. data/features/step_definitions/client_files.rb +14 -0
  78. data/features/step_definitions/command.rb +5 -0
  79. data/features/step_definitions/connect.rb +37 -0
  80. data/features/step_definitions/delete.rb +15 -0
  81. data/features/step_definitions/directory_navigation.rb +26 -0
  82. data/features/step_definitions/error_replies.rb +115 -0
  83. data/features/step_definitions/features.rb +21 -0
  84. data/features/step_definitions/file_structure.rb +16 -0
  85. data/features/step_definitions/generic_send.rb +9 -0
  86. data/features/step_definitions/get.rb +16 -0
  87. data/features/step_definitions/help.rb +18 -0
  88. data/features/step_definitions/invalid_commands.rb +11 -0
  89. data/features/step_definitions/line_endings.rb +7 -0
  90. data/features/step_definitions/list.rb +73 -0
  91. data/features/step_definitions/login.rb +82 -0
  92. data/features/step_definitions/mkdir.rb +9 -0
  93. data/features/step_definitions/mode.rb +15 -0
  94. data/features/step_definitions/mtime.rb +23 -0
  95. data/features/step_definitions/noop.rb +15 -0
  96. data/features/step_definitions/options.rb +9 -0
  97. data/features/step_definitions/passive.rb +3 -0
  98. data/features/step_definitions/pending.rb +3 -0
  99. data/features/step_definitions/port.rb +5 -0
  100. data/features/step_definitions/put.rb +29 -0
  101. data/features/step_definitions/quit.rb +15 -0
  102. data/features/step_definitions/rename.rb +11 -0
  103. data/features/step_definitions/rmdir.rb +9 -0
  104. data/features/step_definitions/server_files.rb +61 -0
  105. data/features/step_definitions/server_title.rb +12 -0
  106. data/features/step_definitions/size.rb +20 -0
  107. data/features/step_definitions/status.rb +9 -0
  108. data/features/step_definitions/success_replies.rb +7 -0
  109. data/features/step_definitions/system.rb +7 -0
  110. data/features/step_definitions/timing.rb +19 -0
  111. data/features/step_definitions/type.rb +15 -0
  112. data/features/support/env.rb +4 -0
  113. data/features/support/example_server.rb +67 -0
  114. data/features/support/file_templates/ascii_unix +4 -0
  115. data/features/support/file_templates/ascii_windows +4 -0
  116. data/features/support/file_templates/binary +0 -0
  117. data/features/support/test_client.rb +250 -0
  118. data/features/support/test_file_templates.rb +33 -0
  119. data/features/support/test_server.rb +293 -0
  120. data/features/support/test_server_files.rb +57 -0
  121. data/ftpd.gemspec +283 -0
  122. data/insecure-test-cert.pem +29 -0
  123. data/investtools-ftpd.gemspec +284 -0
  124. data/lib/ftpd.rb +86 -0
  125. data/lib/ftpd/auth_levels.rb +9 -0
  126. data/lib/ftpd/cmd_abor.rb +13 -0
  127. data/lib/ftpd/cmd_allo.rb +20 -0
  128. data/lib/ftpd/cmd_appe.rb +24 -0
  129. data/lib/ftpd/cmd_auth.rb +21 -0
  130. data/lib/ftpd/cmd_cdup.rb +16 -0
  131. data/lib/ftpd/cmd_cwd.rb +20 -0
  132. data/lib/ftpd/cmd_dele.rb +21 -0
  133. data/lib/ftpd/cmd_eprt.rb +23 -0
  134. data/lib/ftpd/cmd_epsv.rb +30 -0
  135. data/lib/ftpd/cmd_feat.rb +44 -0
  136. data/lib/ftpd/cmd_help.rb +29 -0
  137. data/lib/ftpd/cmd_list.rb +33 -0
  138. data/lib/ftpd/cmd_login.rb +60 -0
  139. data/lib/ftpd/cmd_mdtm.rb +27 -0
  140. data/lib/ftpd/cmd_mkd.rb +23 -0
  141. data/lib/ftpd/cmd_mode.rb +27 -0
  142. data/lib/ftpd/cmd_nlst.rb +27 -0
  143. data/lib/ftpd/cmd_noop.rb +14 -0
  144. data/lib/ftpd/cmd_opts.rb +14 -0
  145. data/lib/ftpd/cmd_pasv.rb +28 -0
  146. data/lib/ftpd/cmd_pbsz.rb +23 -0
  147. data/lib/ftpd/cmd_port.rb +28 -0
  148. data/lib/ftpd/cmd_prot.rb +34 -0
  149. data/lib/ftpd/cmd_pwd.rb +15 -0
  150. data/lib/ftpd/cmd_quit.rb +18 -0
  151. data/lib/ftpd/cmd_rein.rb +13 -0
  152. data/lib/ftpd/cmd_rename.rb +32 -0
  153. data/lib/ftpd/cmd_rest.rb +13 -0
  154. data/lib/ftpd/cmd_retr.rb +24 -0
  155. data/lib/ftpd/cmd_rmd.rb +22 -0
  156. data/lib/ftpd/cmd_site.rb +13 -0
  157. data/lib/ftpd/cmd_size.rb +29 -0
  158. data/lib/ftpd/cmd_smnt.rb +13 -0
  159. data/lib/ftpd/cmd_stat.rb +15 -0
  160. data/lib/ftpd/cmd_stor.rb +25 -0
  161. data/lib/ftpd/cmd_stou.rb +25 -0
  162. data/lib/ftpd/cmd_stru.rb +27 -0
  163. data/lib/ftpd/cmd_syst.rb +16 -0
  164. data/lib/ftpd/cmd_type.rb +28 -0
  165. data/lib/ftpd/command_handler.rb +90 -0
  166. data/lib/ftpd/command_handler_factory.rb +51 -0
  167. data/lib/ftpd/command_handlers.rb +60 -0
  168. data/lib/ftpd/command_loop.rb +80 -0
  169. data/lib/ftpd/command_sequence_checker.rb +58 -0
  170. data/lib/ftpd/config.rb +13 -0
  171. data/lib/ftpd/connection_throttle.rb +56 -0
  172. data/lib/ftpd/connection_tracker.rb +82 -0
  173. data/lib/ftpd/data_connection_helper.rb +123 -0
  174. data/lib/ftpd/disk_file_system.rb +434 -0
  175. data/lib/ftpd/error.rb +21 -0
  176. data/lib/ftpd/exception_translator.rb +32 -0
  177. data/lib/ftpd/exceptions.rb +62 -0
  178. data/lib/ftpd/file_info.rb +115 -0
  179. data/lib/ftpd/file_system_helper.rb +67 -0
  180. data/lib/ftpd/ftp_server.rb +214 -0
  181. data/lib/ftpd/gets_peer_address.rb +41 -0
  182. data/lib/ftpd/insecure_certificate.rb +16 -0
  183. data/lib/ftpd/list_format/eplf.rb +74 -0
  184. data/lib/ftpd/list_format/ls.rb +154 -0
  185. data/lib/ftpd/list_path.rb +28 -0
  186. data/lib/ftpd/null_logger.rb +22 -0
  187. data/lib/ftpd/protocols.rb +60 -0
  188. data/lib/ftpd/read_only_disk_file_system.rb +22 -0
  189. data/lib/ftpd/server.rb +139 -0
  190. data/lib/ftpd/session.rb +220 -0
  191. data/lib/ftpd/session_config.rb +111 -0
  192. data/lib/ftpd/stream.rb +80 -0
  193. data/lib/ftpd/telnet.rb +114 -0
  194. data/lib/ftpd/temp_dir.rb +22 -0
  195. data/lib/ftpd/tls_server.rb +111 -0
  196. data/lib/ftpd/translate_exceptions.rb +68 -0
  197. data/rake_tasks/cucumber.rake +9 -0
  198. data/rake_tasks/default.rake +1 -0
  199. data/rake_tasks/jeweler.rake +52 -0
  200. data/rake_tasks/spec.rake +3 -0
  201. data/rake_tasks/test.rake +2 -0
  202. data/rake_tasks/yard.rake +3 -0
  203. data/spec/command_sequence_checker_spec.rb +83 -0
  204. data/spec/connection_throttle_spec.rb +99 -0
  205. data/spec/connection_tracker_spec.rb +97 -0
  206. data/spec/disk_file_system_spec.rb +320 -0
  207. data/spec/exception_translator_spec.rb +36 -0
  208. data/spec/file_info_spec.rb +59 -0
  209. data/spec/ftp_server_error_spec.rb +13 -0
  210. data/spec/list_format/eplf_spec.rb +61 -0
  211. data/spec/list_format/ls_spec.rb +270 -0
  212. data/spec/list_path_spec.rb +21 -0
  213. data/spec/null_logger_spec.rb +24 -0
  214. data/spec/protocols_spec.rb +139 -0
  215. data/spec/server_spec.rb +81 -0
  216. data/spec/spec_helper.rb +15 -0
  217. data/spec/telnet_spec.rb +75 -0
  218. data/spec/translate_exceptions_spec.rb +40 -0
  219. metadata +404 -0
@@ -0,0 +1,66 @@
1
+ # REFERENCES
2
+
3
+ ## RFCs
4
+
5
+ _This list of references comes from the README of the em-ftpd gem,
6
+ which is licensed under the same MIT license as this gem, and is
7
+ Copyright (c) 2008 James Healy_
8
+
9
+ There are a range of RFCs that together specify the FTP protocol. In
10
+ chronological order, the more useful ones are:
11
+
12
+ * [RFC-854](http://tools.ietf.org/rfc/rfc854.txt) - Telnet Protocol
13
+ Specification
14
+
15
+ * [RFC-959](http://tools.ietf.org/rfc/rfc959.txt) - File Transfer
16
+ Protocol
17
+
18
+ * [RFC-1123](http://tools.ietf.org/rfc/rfc1123.txt) - Requirements for
19
+ Internet Hosts
20
+
21
+ * [RFC-1143](http://tools.ietf.org/rfc/rfc1143.txt) - The Q Method of
22
+ Implementing TELNET Option Negotation
23
+
24
+ * [RFC-2228](http://tools.ietf.org/rfc/rfc2228.txt) - FTP Security
25
+ Extensions
26
+
27
+ * [RFC-2389](http://tools.ietf.org/rfc/rfc2389.txt) - Feature
28
+ negotiation mechanism for the File Transfer Protocol
29
+
30
+ * [RFC-2428](http://tools.ietf.org/rfc/rfc2428.txt) - FTP Extensions
31
+ for IPv6 and NATs
32
+
33
+ * [RFC-2577](http://tools.ietf.org/rfc/rfc2577.txt) - FTP Security
34
+ Considerations
35
+
36
+ * [RFC-2640](http://tools.ietf.org/rfc/rfc2640.txt) -
37
+ Internationalization of the File Transfer Protocol
38
+
39
+ * [RFC-3659](http://tools.ietf.org/rfc/rfc3659.txt) - Extensions to
40
+ FTP
41
+
42
+ * [RFC-4217](http://tools.ietf.org/rfc/rfc4217.txt) -
43
+ Securing FTP with TLS
44
+
45
+ For an english summary that's somewhat more legible than the RFCs, and
46
+ provides some commentary on what features are actually useful or
47
+ relevant 24 years after RFC959 was published:
48
+
49
+ * <http://cr.yp.to/ftp.html>
50
+
51
+ For a history lesson, check out Appendix III of RCF959. It lists the
52
+ preceding (obsolete) RFC documents that relate to file transfers,
53
+ including the ye old RFC114 from 1971, "A File Transfer Protocol"
54
+
55
+ There is a [public test server](http://secureftp-test.com) which is
56
+ very handy for checking out clients, and seeing how at least one
57
+ server behaves.
58
+
59
+ ## How to reliably close a socket (and not lose data)
60
+
61
+ [Why is my TCP not reliable](http://ia600609.us.archive.org/22/items/TheUltimateSo_lingerPageOrWhyIsMyTcpNotReliable/the-ultimate-so_linger-page-or-why-is-my-tcp-not-reliable.html) by Bert Hubert
62
+
63
+ ## LIST output format
64
+
65
+ * [GNU docs for ls](http://www.gnu.org/software/coreutils/manual/html_node/What-information-is-listed.html#What-information-is-listed)
66
+ * [Easily Parsed LIST format (EPLF)](http://cr.yp.to/ftp/list/eplf.html)
@@ -0,0 +1,292 @@
1
+ # RFC compliance
2
+
3
+ This page documents FTPDs compliance (or not) with the RFCs that
4
+ define the FTP protocol.
5
+
6
+ This document is modeled after [this one from the pyftpdlib
7
+ wiki](http://code.google.com/p/pyftpdlib/wiki/RFCsCompliance).
8
+ pyftpdlib is what every FTP library wants to be when it grows up.
9
+
10
+ ## RFC-959 - File Transfer Protocol
11
+
12
+ * Issued: October 1985
13
+ * Status: STANDARD
14
+ * Obsoletes: [RFC-765](http://tools.ietf.org/rfc/rfc765.txt)
15
+ * Updated by:
16
+ [RFC-1123](http://tools.ietf.org/rfc/rfc1123.txt)
17
+ [RFC-2228](http://tools.ietf.org/rfc/rfc2228.txt)
18
+ [RFC-2640](http://tools.ietf.org/rfc/rfc2640.txt)
19
+ [RFC-2773](http://tools.ietf.org/rfc/rfc2773.txt)
20
+ * [link](http://tools.ietf.org/rfc/rfc959.txt)
21
+
22
+ Commands supported:
23
+
24
+ ABOR No --- Abort transfer
25
+ ACCT Yes 0.4.0 Specify user's account
26
+ ALLO Yes 0.2.0 Allocate storage space
27
+ Treated as a NOOP
28
+ APPE Yes 0.4.0 Append to file
29
+ CDUP Yes 0.1.0 Change to parent directory
30
+ CWD Yes 0.1.0 Change working directory
31
+ DELE Yes 0.1.0 Delete file
32
+ HELP Yes 0.2.2 Help
33
+ LIST Yes 0.1.0 List directory
34
+ MKD Yes 0.2.1 Make directory
35
+ MODE Yes 0.1.0 Set transfer mode
36
+ "Stream" mode supported; "Block" and
37
+ "Compressed" are not
38
+ NLST Yes 0.1.0 Name list
39
+ NOOP Yes 0.1.0 No Operation
40
+ PASS Yes 0.1.0 Set user password
41
+ PASV Yes 0.1.0 Set passive mode
42
+ PORT Yes 0.1.0 Set active mode
43
+ PWD Yes 0.1.0 Print working directory
44
+ QUIT Yes 0.1.0 Quit session
45
+ REIN No --- Reinitialize session
46
+ REST No --- Restart transfer
47
+ RETR Yes 0.1.0 Retrieve file
48
+ RMD Yes 0.2.1 Remove directory
49
+ RNFR Yes 0.2.1 Rename file (from)
50
+ RNTO Yes 0.2.1 Rename file (to)
51
+ SITE No --- Site specific commands
52
+ SMNT No --- Structure Mount
53
+ STAT Yes 0.5.0 Server status
54
+ STOR Yes 0.1.0 Store file
55
+ STOU Yes 0.2.2 Store with unique name
56
+ STRU Yes 0.1.0 Set file structure
57
+ Supports "File" structure only. "Record" and
58
+ "Page" are not supported
59
+ SYST Yes 0.2.0 Get system type
60
+ Always returns "UNIX Type: L8"
61
+ TYPE Yes 0.1.0 Set representation type
62
+ Supports ascii non-print and binary-non-print
63
+ only
64
+ USER Yes 0.1.0 Set user
65
+
66
+ ## RFC-1123 - Requirements for Internet Hosts
67
+
68
+ Extends and clarifies some aspects of RFC-959. Introduces new response
69
+ codes 554 and 555.
70
+
71
+ * Issued: October 1989
72
+ * Status: STANDARD
73
+ * [link](http://tools.ietf.org/rfc/rfc1123.txt)
74
+
75
+ The following compliance table is lifted out of the RFC and annotated
76
+ with "C" where FTPD complies, or "E" where compliance is not required.
77
+
78
+ <pre>
79
+ | | | | |S| |
80
+ | | | | |H| |F
81
+ | | | | |O|M|o
82
+ | | |S| |U|U|o
83
+ | | |H| |L|S|t
84
+ | |M|O| |D|T|n
85
+ | |U|U|M| | |o
86
+ | |S|L|A|N|N|t
87
+ | |T|D|Y|O|O|t
88
+ FEATURE |SECTION | | | |T|T|e
89
+ -------------------------------------------|---------------|-|-|-|-|-|--
90
+ Implement TYPE T if same as TYPE N |4.1.2.2 | |x| | | | C
91
+ File/Record transform invertible if poss. |4.1.2.4 | |x| | | | C
92
+ Server-FTP implement PASV |4.1.2.6 |x| | | | | C
93
+ PASV is per-transfer |4.1.2.6 |x| | | | | C
94
+ NLST reply usable in RETR cmds |4.1.2.7 |x| | | | | C
95
+ Implied type for LIST and NLST |4.1.2.7 | |x| | | | C
96
+ SITE cmd for non-standard features |4.1.2.8 | |x| | | | C
97
+ STOU cmd return pathname as specified |4.1.2.9 |x| | | | | C
98
+ Use TCP READ boundaries on control conn. |4.1.2.10 | | | | |x| C
99
+ Server-FTP send only correct reply format |4.1.2.11 |x| | | | | C
100
+ Server-FTP use defined reply code if poss. |4.1.2.11 | |x| | | | C
101
+ New reply code following Section 4.2 |4.1.2.11 | | |x| | | E
102
+ Default data port same IP addr as ctl conn |4.1.2.12 |x| | | | | C
103
+ Server-FTP handle Telnet options |4.1.2.12 |x| | | | | C
104
+ Handle "Experimental" directory cmds |4.1.3.1 | |x| | | | C
105
+ Idle timeout in server-FTP |4.1.3.2 | |x| | | | C
106
+ Configurable idle timeout |4.1.3.2 | |x| | | | C
107
+ Receiver checkpoint data at Restart Marker |4.1.3.4 | |x| | | | E
108
+ Sender assume 110 replies are synchronous |4.1.3.4 | | | | |x| E
109
+ | | | | | | | -
110
+ Support TYPE: | | | | | | | -
111
+ ASCII - Non-Print (AN) |4.1.2.13 |x| | | | | C
112
+ ASCII - Telnet (AT) -- if same as AN |4.1.2.2 | |x| | | | C
113
+ ASCII - Carriage Control (AC) |959 3.1.1.5.2 | | |x| | | E
114
+ EBCDIC - (any form) |959 3.1.1.2 | | |x| | | E
115
+ IMAGE |4.1.2.1 |x| | | | | C
116
+ LOCAL 8 |4.1.2.1 |x| | | | | C
117
+ LOCAL m |4.1.2.1 | | |x| | |2 E
118
+ | | | | | | | -
119
+ Support MODE: | | | | | | | -
120
+ Stream |4.1.2.13 |x| | | | | C
121
+ Block |959 3.4.2 | | |x| | | E
122
+ | | | | | | | -
123
+ Support STRUCTURE: | | | | | | | -
124
+ File |4.1.2.13 |x| | | | | C
125
+ Record |4.1.2.13 |x| | | | |3 E
126
+ Page |4.1.2.3 | | | |x| | E
127
+ | | | | | | | -
128
+ Support commands: | | | | | | | -
129
+ USER |4.1.2.13 |x| | | | | C
130
+ PASS |4.1.2.13 |x| | | | | C
131
+ ACCT |4.1.2.13 |x| | | | | C
132
+ CWD |4.1.2.13 |x| | | | | C
133
+ CDUP |4.1.2.13 |x| | | | | C
134
+ SMNT |959 5.3.1 | | |x| | | E
135
+ REIN |959 5.3.1 | | |x| | | E
136
+ QUIT |4.1.2.13 |x| | | | | C
137
+ | | | | | | | -
138
+ PORT |4.1.2.13 |x| | | | | C
139
+ PASV |4.1.2.6 |x| | | | | C
140
+ TYPE |4.1.2.13 |x| | | | |1 C
141
+ STRU |4.1.2.13 |x| | | | |1 C
142
+ MODE |4.1.2.13 |x| | | | |1 C
143
+ | | | | | | | -
144
+ RETR |4.1.2.13 |x| | | | | C
145
+ STOR |4.1.2.13 |x| | | | | C
146
+ STOU |959 5.3.1 | | |x| | | C
147
+ APPE |4.1.2.13 |x| | | | | C
148
+ ALLO |959 5.3.1 | | |x| | | C
149
+ REST |959 5.3.1 | | |x| | | E
150
+ RNFR |4.1.2.13 |x| | | | | C
151
+ RNTO |4.1.2.13 |x| | | | | C
152
+ ABOR |959 5.3.1 | | |x| | | E
153
+ DELE |4.1.2.13 |x| | | | | C
154
+ RMD |4.1.2.13 |x| | | | | C
155
+ MKD |4.1.2.13 |x| | | | | C
156
+ PWD |4.1.2.13 |x| | | | | C
157
+ LIST |4.1.2.13 |x| | | | | C
158
+ NLST |4.1.2.13 |x| | | | | C
159
+ SITE |4.1.2.8 | | |x| | | E
160
+ STAT |4.1.2.13 |x| | | | | C
161
+ SYST |4.1.2.13 |x| | | | | C
162
+ HELP |4.1.2.13 |x| | | | | C
163
+ NOOP |4.1.2.13 |x| | | | | C
164
+
165
+ Footnotes:
166
+
167
+ (1) For the values shown earlier.
168
+ (2) Here m is number of bits in a memory word.
169
+ (3) Required for host with record-structured file system, optional
170
+ otherwise.
171
+
172
+ </pre>
173
+
174
+ ## RFC-2228 - FTP Security Extensions
175
+
176
+ Specifies several security extensions to the base FTP protocol defined
177
+ in RFC-959. New commands: AUTH, ADAT, PROT, PBSZ, CCC, MIC, CONF, and
178
+ ENC. New response codes: 232, 234, 235, 334, 335, 336, 431, 533, 534,
179
+ 535, 536, 537, 631, 632, and 633.
180
+
181
+ <pre>
182
+ AUTH Yes 0.1.0 Authentication/Security Mechanism
183
+ ADAT No --- Authentication/Security Data
184
+ PROT Yes 0.1.0 Data Channel Protection Level
185
+ PBSZ Yes 0.1.0 Protection Buffer Size
186
+ CCC No --- Clear Command Channel
187
+ MIC No --- Integrity Protect Command
188
+ CONF No --- Confidentiality Protected Command
189
+ ENC No --- Privacy Protected Command
190
+ </pre>
191
+
192
+ ## RFC-2389 - Feature negotiation mechanism for the File Transfer Protocol
193
+
194
+ Introduces the new FEAT and OPTS commands.
195
+
196
+ * Issued: August 1998
197
+ * Status: PROPOSED STANDARD
198
+ * [link](http://tools.ietf.org/rfc/rfc2389.txt)
199
+
200
+ <pre>
201
+ FEAT Yes 0.6.0 List new supported commands
202
+ OPTS Yes 0.6.0 Set options for certain commands
203
+ </pre>
204
+
205
+ ## RFC-2428 - FTP Extensions for IPv6 and NATs
206
+
207
+ Introduces the new commands EPRT and EPSV extending FTP to enable its
208
+ use over various network protocols, and the new response codes 522 and
209
+ 229.
210
+
211
+ * Issued: September 1998
212
+ * Status: PROPOSED STANDARD
213
+ * [link](http://tools.ietf.org/rfc/rfc2428.txt)
214
+
215
+ <pre>
216
+ EPRT Yes 0.9.0 Set active data connection over IPv4 or IPv6
217
+ EPSV Yes 0.9.0 Set passive data connection over IPv4 or IPv6
218
+ </pre>
219
+
220
+ ##RFC-2577 - FTP Security Considerations
221
+
222
+ Provides several configuration and implementation suggestions to
223
+ mitigate some security concerns, including limiting failed password
224
+ attempts and third-party "proxy FTP" transfers, which can be used in
225
+ "bounce attacks".
226
+
227
+ * Issued: May 1999
228
+ * Status: INFORMATIONAL
229
+ * [link](http://tools.ietf.org/rfc/rfc2577.txt)
230
+
231
+ <pre>
232
+ FTP bounce protection
233
+ Restrict PASV/PORT to non-priv. ports Yes 0.5.0
234
+ Disconnect after so many wrong auths. Yes 0.6.0
235
+ Delay on invalid password Yes 0.6.0
236
+ Per-source IP limit Yes 0.6.0
237
+ Do not reject wrong usernames Yes 0.1.0
238
+ Port stealing protection Yes 0.1.0
239
+ </pre>
240
+
241
+ ## RFC-2640 - Internationalization of the File Transfer Protocol
242
+
243
+ Extends the FTP protocol to support multiple character sets, in
244
+ addition to the original 7-bit ASCII. Introduces the new LANG command.
245
+
246
+ * Issued: July 1999
247
+ * Status: PROPOSED STANDARD
248
+ * [link](http://tools.ietf.org/rfc/rfc2640.txt)
249
+
250
+ <pre>
251
+ LANG command No ---
252
+ UNICODE No ---
253
+ </pre>
254
+
255
+ ## RFC-3659 - Extensions to FTP
256
+
257
+ Four new commands are added: "SIZE", "MDTM", "MLST", and "MLSD". The existing command "REST" is modified.
258
+
259
+ * Issued: March 2007
260
+ * Status: PROPOSED STANDARD
261
+ * Updates: [RFC-959](http://tools.ietf.org/rfc/rfc959.txt)
262
+ * [link](http://tools.ietf.org/rfc/rfc3659.txt)
263
+
264
+ <pre>
265
+ MDTM command Yes --- Get file's last modification time
266
+ MLSD command No --- Get directory list in a standardized form.
267
+ MLST command No --- Get file information in a standardized form.
268
+ SIZE command Yes --- Get file size.
269
+ TVSF mechanism No --- Unix-like file system naming conventions
270
+ Min. MLST facts No ---
271
+ GMT timestamps Yes ---
272
+ </pre>
273
+
274
+ ##RFC-4217 - Securing FTP with TLS
275
+
276
+ Provides a description on how to implement TLS as a security mechanism to secure FTP clients and/or servers.
277
+
278
+ * Issued: October 2005
279
+ * Status: STANDARD
280
+ * Updates:
281
+ [RFC-959](http://tools.ietf.org/rfc/rfc959.txt)
282
+ [RFC-2246](http://tools.ietf.org/rfc/rfc2246.txt)
283
+ [RFC-2228](http://tools.ietf.org/rfc/rfc2228.txt)
284
+ * [link](http://tools.ietf.org/rfc/rfc4217.txt)
285
+
286
+ <pre>
287
+ AUTH Yes 0.1.0 Authentication/Security Mechanism
288
+ CCC No --- Clear Command Channel
289
+ PBSZ Yes 0.1.0 Protection Buffer Size
290
+ PROT Yes 0.1.0 Data Channel Protection Level.
291
+ Support only "Private" level
292
+ </pre>
@@ -0,0 +1,275 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ unless $:.include?(File.dirname(__FILE__) + '/../lib')
4
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
5
+ end
6
+
7
+ require 'ftpd'
8
+ require 'ipaddr'
9
+ require 'optparse'
10
+
11
+ module Example
12
+
13
+ # Command-line option parser
14
+
15
+ class Arguments
16
+
17
+ attr_reader :account
18
+ attr_reader :auth_level
19
+ attr_reader :debug
20
+ attr_reader :eplf
21
+ attr_reader :interface
22
+ attr_reader :password
23
+ attr_reader :port
24
+ attr_reader :read_only
25
+ attr_reader :session_timeout
26
+ attr_reader :tls
27
+ attr_reader :user
28
+
29
+ def initialize(argv)
30
+ @interface = '127.0.0.1'
31
+ @tls = :explicit
32
+ @port = 0
33
+ @auth_level = 'password'
34
+ @user = ENV['LOGNAME']
35
+ @password = ''
36
+ @account = ''
37
+ @session_timeout = default_session_timeout
38
+ @log = nil
39
+ op = option_parser
40
+ op.parse!(argv)
41
+ rescue OptionParser::ParseError => e
42
+ $stderr.puts e
43
+ exit(1)
44
+ end
45
+
46
+ private
47
+
48
+ def option_parser
49
+ op = OptionParser.new do |op|
50
+ op.on('-p', '--port N', Integer, 'Bind to a specific port') do |t|
51
+ @port = t
52
+ end
53
+ op.on('-i', '--interface IP', 'Bind to a specific interface') do |t|
54
+ @interface = t
55
+ end
56
+ op.on('--tls [TYPE]', [:off, :explicit, :implicit],
57
+ 'Select TLS support (off, explicit, implicit)',
58
+ 'default = off') do |t|
59
+ @tls = t
60
+ end
61
+ op.on('--eplf', 'LIST uses EPLF format') do |t|
62
+ @eplf = t
63
+ end
64
+ op.on('--read-only', 'Prohibit put, delete, rmdir, etc.') do |t|
65
+ @read_only = t
66
+ end
67
+ op.on('--auth [LEVEL]', [:user, :password, :account],
68
+ 'Set authorization level (user, password, account)',
69
+ 'default = password') do |t|
70
+ @auth_level = t
71
+ end
72
+ op.on('-U', '--user NAME', 'User for authentication',
73
+ 'defaults to current user') do |t|
74
+ @user = t
75
+ end
76
+ op.on('-P', '--password PW', 'Password for authentication',
77
+ 'defaults to empty string') do |t|
78
+ @password = t
79
+ end
80
+ op.on('-A', '--account PW', 'Account for authentication',
81
+ 'defaults to empty string') do |t|
82
+ @account = t
83
+ end
84
+ op.on('--timeout SEC', Integer, 'Session idle timeout',
85
+ "defaults to #{default_session_timeout}") do |t|
86
+ @session_timeout = t
87
+ end
88
+ op.on('-d', '--debug', 'Write server debug log to stdout') do |t|
89
+ @debug = t
90
+ end
91
+ end
92
+ end
93
+
94
+ def default_session_timeout
95
+ Ftpd::FtpServer::DEFAULT_SESSION_TIMEOUT
96
+ end
97
+
98
+ end
99
+ end
100
+
101
+ module Example
102
+
103
+ # The FTP server requires and instance of a _driver_ which can
104
+ # authenticate users and create a file system drivers for a given
105
+ # user. You can use this as a template for creating your own
106
+ # driver.
107
+
108
+ class Driver
109
+
110
+ # Your driver's initialize method can be anything you need. Ftpd
111
+ # does not create an instance of your driver.
112
+
113
+ def initialize(user, password, account, data_dir, read_only)
114
+ @user = user
115
+ @password = password
116
+ @account = account
117
+ @data_dir = data_dir
118
+ @read_only = read_only
119
+ end
120
+
121
+ # Return true if the user should be allowed to log in.
122
+ # @param user [String]
123
+ # @param password [String]
124
+ # @param account [String]
125
+ # @return [Boolean]
126
+ #
127
+ # Depending upon the server's auth_level, some of these parameters
128
+ # may be nil. A parameter with a nil value is not required for
129
+ # authentication. Here are the parameters that are non-nil for
130
+ # each auth_level:
131
+ # * :user (user)
132
+ # * :password (user, password)
133
+ # * :account (user, password, account)
134
+
135
+ def authenticate(user, password, account)
136
+ user == @user &&
137
+ (password.nil? || password == @password) &&
138
+ (account.nil? || account == @account)
139
+ end
140
+
141
+ # Return the file system to use for a user.
142
+ # @param user [String]
143
+ # @return A file system driver that quacks like {Ftpd::DiskFileSystem}
144
+
145
+ def file_system(user)
146
+ if @read_only
147
+ Ftpd::ReadOnlyDiskFileSystem
148
+ else
149
+ Ftpd::DiskFileSystem
150
+ end.new(@data_dir)
151
+ end
152
+
153
+ end
154
+ end
155
+
156
+ module Example
157
+ class Main
158
+
159
+ include Ftpd::InsecureCertificate
160
+
161
+ def initialize(argv)
162
+ @args = Arguments.new(argv)
163
+ @data_dir = Ftpd::TempDir.make
164
+ create_files
165
+ @driver = Driver.new(user, password, account,
166
+ @data_dir, @args.read_only)
167
+ @server = Ftpd::FtpServer.new(@driver)
168
+ configure_server
169
+ @server.start
170
+ display_connection_info
171
+ create_connection_script
172
+ end
173
+
174
+ def run
175
+ wait_until_stopped
176
+ end
177
+
178
+ private
179
+
180
+ def configure_server
181
+ @server.interface = @args.interface
182
+ @server.port = @args.port
183
+ @server.tls = @args.tls
184
+ @server.certfile_path = insecure_certfile_path
185
+ if @args.eplf
186
+ @server.list_formatter = Ftpd::ListFormat::Eplf
187
+ end
188
+ @server.auth_level = auth_level
189
+ @server.session_timeout = @args.session_timeout
190
+ @server.log = make_log
191
+ end
192
+
193
+ def auth_level
194
+ Ftpd.const_get("AUTH_#{@args.auth_level.upcase}")
195
+ end
196
+
197
+ def create_files
198
+ create_file 'README',
199
+ "This file, and the directory it is in, will go away\n"
200
+ "When this example exits.\n"
201
+ end
202
+
203
+ def create_file(path, contents)
204
+ full_path = File.expand_path(path, @data_dir)
205
+ FileUtils.mkdir_p File.dirname(full_path)
206
+ File.open(full_path, 'w') do |file|
207
+ file.write contents
208
+ end
209
+ end
210
+
211
+ def display_connection_info
212
+ puts "Interface: #{@server.interface}"
213
+ puts "Port: #{@server.bound_port}"
214
+ puts "User: #{user.inspect}"
215
+ puts "Pass: #{password.inspect}" if auth_level >= Ftpd::AUTH_PASSWORD
216
+ puts "Account: #{account.inspect}" if auth_level >= Ftpd::AUTH_ACCOUNT
217
+ puts "TLS: #{@args.tls}"
218
+ puts "Directory: #{@data_dir}"
219
+ puts "URI: #{uri}"
220
+ puts "PID: #{$$}"
221
+ end
222
+
223
+ def uri
224
+ "ftp://#{connection_host}:#{@server.bound_port}"
225
+ end
226
+
227
+ def create_connection_script
228
+ command_path = '/tmp/connect-to-example-ftp-server.sh'
229
+ File.open(command_path, 'w') do |file|
230
+ file.puts "#!/bin/bash"
231
+ file.puts "ftp $FTP_ARGS #{connection_host} #{@server.bound_port}"
232
+ end
233
+ system("chmod +x #{command_path}")
234
+ puts "Connection script written to #{command_path}"
235
+ end
236
+
237
+ def wait_until_stopped
238
+ puts "FTP server started. Press ENTER or c-C to stop it"
239
+ $stdout.flush
240
+ begin
241
+ gets
242
+ rescue Interrupt
243
+ puts "Interrupt"
244
+ end
245
+ end
246
+
247
+ def user
248
+ @args.user
249
+ end
250
+
251
+ def password
252
+ @args.password
253
+ end
254
+
255
+ def account
256
+ @args.account
257
+ end
258
+
259
+ def make_log
260
+ @args.debug && Logger.new($stdout)
261
+ end
262
+
263
+ def connection_host
264
+ addr = IPAddr.new(@server.interface)
265
+ if addr.ipv6?
266
+ '::1'
267
+ else
268
+ '127.0.0.1'
269
+ end
270
+ end
271
+
272
+ end
273
+ end
274
+
275
+ Example::Main.new(ARGV).run if $0 == __FILE__