Source code: org/finj/profile/StrictFTPServerProfile.java
1 package org.finj.profile;
2
3 import org.finj.FTPCommand;
4 import org.finj.FTPException;
5 import org.finj.FTPResponse;
6 import org.finj.FTPServerProfile;
7
8 /**
9 * This implementation of the <code>org.finj.FTPServerProfile</code>
10 * interface is a strict, word by word transcription of RFC959:
11 * FTP servers that work with this profile are 100% compatible.
12 *
13 * Copyright (C)
14 *
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 * @author Javier Iglesias -- jiglesias@users.sourceforge.net
30 * @version $Id: StrictFTPServerProfile.java,v 1.2 2003/05/27 15:50:24 jiglesia Exp $
31 */
32 public class StrictFTPServerProfile extends Object implements FTPServerProfile {
33
34 /**
35 * Constructs a new instance of this class.
36 *
37 * @since v1.0
38 */
39 public StrictFTPServerProfile ( ) {;}
40
41 /**
42 * Checks if the <code>response</code> is the last that
43 * one has to expect after establishing the control
44 * connection with a server.
45 *
46 * @param response
47 * @return <code>true</code> if the <code>response</code> is the last
48 * to expect from server when establishing the control connection.
49 * @exception FTPException <code>response</code> is not a valid response
50 * when establishing a control connection.
51 * @since v1.2
52 */
53 public boolean isControlConnectionReady ( FTPResponse response ) throws FTPException {
54 switch ( response.getCode() ) {
55 case FTPResponse.CONTROL_CONNECTION_OPENED_CODE : // success - 220
56 // this response is ok
57 return true;
58 case FTPResponse.WILL_BE_READY_IN_MINUTES_CODE : // intermed - 120
59 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
60 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
61 default :
62 throw FTPException.createInvalidResponseException(this, response.getCode(), "open control connection");
63 }
64 }
65
66 /**
67 * Checks if the <code>response</code> is the last that
68 * one has to expect for the <code>command</code>.
69 *
70 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
71 * @param command <code>org.finj.FTPCommand</code> sent to the server.
72 * @param response <code>org.finj.FTPResponse</code> returned by the server.
73 * @return <code>true</code> if the <code>response</code> is the last
74 * to expect from server for the <code>command</code>.
75 * @exception FTPException <code>response</code> is not a valid answer
76 * for the <code>command</code>.
77 * @since v1.0
78 */
79 public boolean isCommandCompleted ( FTPCommand command, FTPResponse response ) throws FTPException {
80 switch ( command.getCode() ) {
81 case FTPCommand.USER_NAME :
82 return isUSERCommandCompleted(response);
83 case FTPCommand.PASSWORD :
84 return isPASSCommandCompleted(response);
85 case FTPCommand.ACCOUNT :
86 return isACCTCommandCompleted(response);
87 case FTPCommand.CHANGE_WORKING_DIRECTORY :
88 return isCWDCommandCompleted(response);
89 case FTPCommand.CHANGE_TO_PARENT_DIRECTORY :
90 return isCDUPCommandCompleted(response);
91 case FTPCommand.STRUCTURE_MOUNT :
92 return isSMNTCommandCompleted(response);
93 case FTPCommand.REINITIALIZE :
94 return isREINCommandCompleted(response);
95 case FTPCommand.LOGOUT :
96 return isQUITCommandCompleted(response);
97 case FTPCommand.DATA_PORT :
98 return isPORTCommandCompleted(response);
99 case FTPCommand.PASSIVE :
100 return isPASVCommandCompleted(response);
101 case FTPCommand.REPRESENTATION_TYPE :
102 return isTYPECommandCompleted(response);
103 case FTPCommand.FILE_STRUCTURE :
104 return isSTRUCommandCompleted(response);
105 case FTPCommand.TRANSFER_MODE :
106 return isMODECommandCompleted(response);
107 case FTPCommand.RETRIEVE :
108 return isRETRCommandCompleted(response);
109 case FTPCommand.STORE_FILE :
110 return isSTORCommandCompleted(response);
111 case FTPCommand.STORE_UNIQUE_FILE :
112 return isSTOUCommandCompleted(response);
113 case FTPCommand.APPEND_WITH_CREATE :
114 return isAPPECommandCompleted(response);
115 case FTPCommand.ALLOCATE :
116 return isALLOCommandCompleted(response);
117 case FTPCommand.RESTART :
118 return isRESTCommandCompleted(response);
119 case FTPCommand.RENAME_FROM :
120 return isRNFRCommandCompleted(response);
121 case FTPCommand.RENAME_TO :
122 return isRNTOCommandCompleted(response);
123 case FTPCommand.ABORT :
124 return isABORCommandCompleted(response);
125 case FTPCommand.DELETE_FILE :
126 return isDELECommandCompleted(response);
127 case FTPCommand.REMOVE_DIRECTORY :
128 return isRMDCommandCompleted(response);
129 case FTPCommand.MAKE_DIRECTORY :
130 return isMKDCommandCompleted(response);
131 case FTPCommand.PRINT_WORKING_DIRECTORY :
132 return isPWDCommandCompleted(response);
133 case FTPCommand.LIST :
134 return isLISTCommandCompleted(response);
135 case FTPCommand.NAME_LIST :
136 return isNLSTCommandCompleted(response);
137 case FTPCommand.SITE_PARAMETERS :
138 return isSITECommandCompleted(response);
139 case FTPCommand.SYSTEM :
140 return isSYSTCommandCompleted(response);
141 case FTPCommand.STATUS :
142 return isSTATCommandCompleted(response);
143 //FIXME: does it belong here ?! case FTPCommand.HELP :
144 //FIXME: does it belong here ?! return isHELPCommandCompleted(response);
145 case FTPCommand.NO_OPERATION :
146 return isNOOPCommandCompleted(response);
147 }
148 throw new FTPException(this, command.getCode(), " is not a valid FTP command");
149 }
150
151
152
153 /**
154 * Checks if the <code>response</code> is the last that
155 * one has to expect for the <code>command</code>.
156 *
157 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
158 * @param response response from server to check.
159 * @return <code>true</code> if the <code>response</code> is
160 * the last to expect from server for the USER command.
161 * @exception FTPException <code>response</code> is not a valid answer
162 * for the <code>command</code>.
163 * @since v1.0
164 */
165 protected boolean isUSERCommandCompleted ( FTPResponse response ) throws FTPException {
166 switch ( response.getCode() ) {
167 case FTPResponse.USER_LOGGED_IN_CODE : // success - 230
168 case FTPResponse.USERNAME_OK_NEED_PASSWORD_CODE : // intermed - 331
169 case FTPResponse.NEED_ACCOUNT_FOR_LOGIN_CODE : // intermed - 332
170 // this response is ok
171 return true;
172 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
173 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE: // failure - 500
174 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
175 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
176 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
177 default :
178 throw FTPException.createInvalidResponseException(this, response.getCode(), "USER");
179 }
180 }
181
182 /**
183 * Checks if the <code>response</code> is the last that
184 * one has to expect for the <code>command</code>.
185 *
186 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
187 * @param response response from server to check.
188 * @return <code>true</code> if the <code>response</code> is
189 * the last to expect from server for the PASS command.
190 * @exception FTPException <code>response</code> is not a valid answer
191 * for the <code>command</code>.
192 * @since v1.0
193 */
194 protected boolean isPASSCommandCompleted ( FTPResponse response ) throws FTPException {
195 switch ( response.getCode() ) {
196 case FTPResponse.SUPERFLOUS_COMMAND_CODE : // success - 202
197 case FTPResponse.USER_LOGGED_IN_CODE : // success - 230
198 case FTPResponse.NEED_ACCOUNT_FOR_LOGIN_CODE : // intermed - 332
199 // this response is ok
200 return true;
201 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
202 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
203 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
204 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
205 case FTPResponse.BAD_COMMAND_SEQUENCE_CODE : // failure - 503
206 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
207 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
208 default :
209 throw FTPException.createInvalidResponseException(this, response.getCode(), "PASS");
210 }
211 }
212
213 /**
214 * Checks if the <code>response</code> is the last that
215 * one has to expect for the <code>command</code>.
216 *
217 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
218 * @param response response from server to check.
219 * @return <code>true</code> if the <code>response</code> is
220 * the last to expect from server for the ACCT command.
221 * @exception FTPException <code>response</code> is not a valid answer
222 * for the <code>command</code>.
223 * @since v1.0
224 */
225 protected boolean isACCTCommandCompleted ( FTPResponse response ) throws FTPException {
226 switch ( response.getCode() ) {
227 case FTPResponse.SUPERFLOUS_COMMAND_CODE : // success - 202
228 case FTPResponse.USER_LOGGED_IN_CODE : // success - 230
229 // this response is ok
230 return true;
231 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
232 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
233 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
234 case FTPResponse.BAD_COMMAND_SEQUENCE_CODE : // failure - 503
235 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
236 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
237 default :
238 throw FTPException.createInvalidResponseException(this, response.getCode(), "ACCT");
239 }
240 }
241
242 /**
243 * Checks if the <code>response</code> is the last that
244 * one has to expect for the <code>command</code>.
245 *
246 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
247 * @param response response from server to check.
248 * @return <code>true</code> if the <code>response</code> is
249 * the last to expect from server for the CWD command.
250 * @exception FTPException <code>response</code> is not a valid answer
251 * for the <code>command</code>.
252 * @since v1.0
253 */
254 protected boolean isCWDCommandCompleted ( FTPResponse response ) throws FTPException {
255 switch ( response.getCode() ) {
256 case FTPResponse.REQUESTED_FILE_ACTION_OK_CODE : // success - 250
257 // this response is ok
258 return true;
259 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
260 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
261 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
262 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
263 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
264 case FTPResponse.PERMANENTLY_UNAVAILABLE_FILE_CODE : // failure - 550
265 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
266 default :
267 throw FTPException.createInvalidResponseException(this, response.getCode(), "CWD");
268 }
269 }
270
271 /**
272 * Checks if the <code>response</code> is the last that
273 * one has to expect for the <code>command</code>.
274 *
275 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
276 * @param response response from server to check.
277 * @return <code>true</code> if the <code>response</code> is
278 * the last to expect from server for the CDUP command.
279 * @exception FTPException <code>response</code> is not a valid answer
280 * for the <code>command</code>.
281 * @since v1.0
282 */
283 protected boolean isCDUPCommandCompleted ( FTPResponse response ) throws FTPException {
284 switch ( response.getCode() ) {
285 // NB: should be code 200 (FTPResponse.POSITIVE_COMPLETION_RESPONSE_CODE) according to RFC959...
286 case FTPResponse.REQUESTED_FILE_ACTION_OK_CODE : // success - 250
287 // this response is ok
288 return true;
289 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
290 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
291 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
292 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
293 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
294 case FTPResponse.PERMANENTLY_UNAVAILABLE_FILE_CODE : // failure - 550
295 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
296 default :
297 throw FTPException.createInvalidResponseException(this, response.getCode(), "CDUP");
298 }
299 }
300
301 /**
302 * Checks if the <code>response</code> is the last that
303 * one has to expect for the <code>command</code>.
304 *
305 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
306 * @param response response from server to check.
307 * @return <code>true</code> if the <code>response</code> is
308 * the last to expect from server for the SMNT command.
309 * @exception FTPException <code>response</code> is not a valid answer
310 * for the <code>command</code>.
311 * @since v1.0
312 */
313 protected boolean isSMNTCommandCompleted ( FTPResponse response ) throws FTPException {
314 switch ( response.getCode() ) {
315 case FTPResponse.SUPERFLOUS_COMMAND_CODE : // success - 202
316 case FTPResponse.REQUESTED_FILE_ACTION_OK_CODE : // success - 250
317 // this response is ok
318 return true;
319 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
320 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
321 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
322 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
323 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
324 case FTPResponse.PERMANENTLY_UNAVAILABLE_FILE_CODE : // failure - 550
325 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
326 default :
327 throw FTPException.createInvalidResponseException(this, response.getCode(), "SMNT");
328 }
329 }
330
331 /**
332 * Checks if the <code>response</code> is the last that
333 * one has to expect for the <code>command</code>.
334 *
335 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
336 * @param response response from server to check.
337 * @return <code>true</code> if the <code>response</code> is
338 * the last to expect from server for the REIN command.
339 * @exception FTPException <code>response</code> is not a valid answer
340 * for the <code>command</code>.
341 * @since v1.0
342 */
343 protected boolean isREINCommandCompleted ( FTPResponse response ) throws FTPException {
344 switch ( response.getCode() ) {
345 case FTPResponse.CONTROL_CONNECTION_OPENED_CODE : // success - 220
346 // this response is ok
347 return true;
348 case FTPResponse.WILL_BE_READY_IN_MINUTES_CODE : // intermed - 120
349 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
350 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
351 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
352 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
353 default :
354 throw FTPException.createInvalidResponseException(this, response.getCode(), "REIN");
355 }
356 }
357
358 /**
359 * Checks if the <code>response</code> is the last that
360 * one has to expect for the <code>command</code>.
361 *
362 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
363 * @param response response from server to check.
364 * @return <code>true</code> if the <code>response</code> is
365 * the last to expect from server for the QUIT command.
366 * @exception FTPException <code>response</code> is not a valid answer
367 * for the <code>command</code>.
368 * @since v1.0
369 */
370 protected boolean isQUITCommandCompleted ( FTPResponse response ) throws FTPException {
371 switch ( response.getCode() ) {
372 case FTPResponse.CONTROL_CONNECTION_CLOSED_CODE : // success - 221
373 // this response is ok
374 return true;
375 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
376 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
377 default :
378 throw FTPException.createInvalidResponseException(this, response.getCode(), "QUIT");
379 }
380 }
381
382 /**
383 * Checks if the <code>response</code> is the last that
384 * one has to expect for the <code>command</code>.
385 *
386 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
387 * @param response response from server to check.
388 * @return <code>true</code> if the <code>response</code> is
389 * the last to expect from server for the PORT command.
390 * @exception FTPException <code>response</code> is not a valid answer
391 * for the <code>command</code>.
392 * @since v1.0
393 */
394 protected boolean isPORTCommandCompleted ( FTPResponse response ) throws FTPException {
395 switch ( response.getCode() ) {
396 case FTPResponse.POSITIVE_COMPLETION_RESPONSE_CODE : // success - 200
397 // this response is ok
398 return true;
399 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
400 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
401 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
402 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
403 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
404 default :
405 throw FTPException.createInvalidResponseException(this, response.getCode(), "PORT");
406 }
407 }
408
409 /**
410 * Checks if the <code>response</code> is the last that
411 * one has to expect for the <code>command</code>.
412 *
413 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
414 * @param response response from server to check.
415 * @return <code>true</code> if the <code>response</code> is
416 * the last to expect from server for the PASV command.
417 * @exception FTPException <code>response</code> is not a valid answer
418 * for the <code>command</code>.
419 * @since v1.0
420 */
421 protected boolean isPASVCommandCompleted ( FTPResponse response ) throws FTPException {
422 switch ( response.getCode() ) {
423 case FTPResponse.ENTERING_PASSIVE_MODE_CODE : // success - 227
424 // this response is ok
425 return true;
426 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
427 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
428 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
429 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
430 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
431 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
432 default :
433 throw FTPException.createInvalidResponseException(this, response.getCode(), "PASV");
434 }
435 }
436
437 /**
438 * Checks if the <code>response</code> is the last that
439 * one has to expect for the <code>command</code>.
440 *
441 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
442 * @param response response from server to check.
443 * @return <code>true</code> if the <code>response</code> is
444 * the last to expect from server for the TYPE command.
445 * @exception FTPException <code>response</code> is not a valid answer
446 * for the <code>command</code>.
447 * @since v1.0
448 */
449 protected boolean isTYPECommandCompleted ( FTPResponse response ) throws FTPException {
450 switch ( response.getCode() ) {
451 case FTPResponse.POSITIVE_COMPLETION_RESPONSE_CODE : // success - 200
452 // this response is ok
453 return true;
454 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
455 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
456 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
457 case FTPResponse.COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER_CODE : // failure - 504
458 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
459 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
460 default :
461 throw FTPException.createInvalidResponseException(this, response.getCode(), "TYPE");
462 }
463 }
464
465 /**
466 * Checks if the <code>response</code> is the last that
467 * one has to expect for the <code>command</code>.
468 *
469 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
470 * @param response response from server to check.
471 * @return <code>true</code> if the <code>response</code> is
472 * the last to expect from server for the STRU command.
473 * @exception FTPException <code>response</code> is not a valid answer
474 * for the <code>command</code>.
475 * @since v1.0
476 */
477 protected boolean isSTRUCommandCompleted ( FTPResponse response ) throws FTPException {
478 switch ( response.getCode() ) {
479 case FTPResponse.POSITIVE_COMPLETION_RESPONSE_CODE : // success - 200
480 // this response is ok
481 return true;
482 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
483 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
484 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
485 case FTPResponse.COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER_CODE : // failure - 504
486 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
487 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
488 default :
489 throw FTPException.createInvalidResponseException(this, response.getCode(), "STRU");
490 }
491 }
492
493 /**
494 * Checks if the <code>response</code> is the last that
495 * one has to expect for the <code>command</code>.
496 *
497 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
498 * @param response response from server to check.
499 * @return <code>true</code> if the <code>response</code> is
500 * the last to expect from server for the MODE command.
501 * @exception FTPException <code>response</code> is not a valid answer
502 * for the <code>command</code>.
503 * @since v1.0
504 */
505 protected boolean isMODECommandCompleted ( FTPResponse response ) throws FTPException {
506 switch ( response.getCode() ) {
507 case FTPResponse.POSITIVE_COMPLETION_RESPONSE_CODE : // success - 200
508 // this response is ok
509 return true;
510 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
511 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
512 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
513 case FTPResponse.COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER_CODE : // failure - 504
514 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
515 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
516 default :
517 throw FTPException.createInvalidResponseException(this, response.getCode(), "MODE");
518 }
519 }
520
521 /**
522 * Checks if the <code>response</code> is the last that
523 * one has to expect for the <code>command</code>.
524 *
525 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
526 * @param response response from server to check.
527 * @return <code>true</code> if the <code>response</code> is
528 * the last to expect from server for the RETR command.
529 * @exception FTPException <code>response</code> is not a valid answer
530 * for the <code>command</code>.
531 * @since v1.0
532 */
533 protected boolean isRETRCommandCompleted ( FTPResponse response ) throws FTPException {
534 switch ( response.getCode() ) {
535 case FTPResponse.RESTART_MARKER_RESPONSE_CODE : // intermed - 110
536 // this response is ok, but more replies to come
537 return false;
538 case FTPResponse.DATA_CONNECTION_ABOUT_TO_BE_OPENED_CODE : // intermed - 150
539 // this response is ok
540 return true;
541 case FTPResponse.DATA_CONNECTION_ALREADY_OPENED_CODE : // intermed - 125
542 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
543 case FTPResponse.CAN_T_OPEN_DATA_CONNECTION_CODE : // failure - 425
544 case FTPResponse.DATA_CONNECTION_ABORTED_CODE : // failure - 426
545 case FTPResponse.TRANSIENT_UNAVAILABLE_FILE_CODE : // failure - 450
546 case FTPResponse.TRANSIENT_LOCAL_PROCESSING_ERROR_CODE : // failure - 451
547 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
548 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
549 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
550 case FTPResponse.PERMANENTLY_UNAVAILABLE_FILE_CODE : // failure - 550
551 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
552 default :
553 throw FTPException.createInvalidResponseException(this, response.getCode(), "RETR");
554 }
555 }
556
557 /**
558 * Checks if the <code>response</code> is the last that
559 * one has to expect for the <code>command</code>.
560 *
561 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
562 * @param response response from server to check.
563 * @return <code>true</code> if the <code>response</code> is
564 * the last to expect from server for the STOR command.
565 * @exception FTPException <code>response</code> is not a valid answer
566 * for the <code>command</code>.
567 * @since v1.0
568 */
569 protected boolean isSTORCommandCompleted ( FTPResponse response ) throws FTPException {
570 switch ( response.getCode() ) {
571 case FTPResponse.RESTART_MARKER_RESPONSE_CODE : // intermed - 110
572 // this response is ok, but more replies to come
573 return false;
574 case FTPResponse.DATA_CONNECTION_ABOUT_TO_BE_OPENED_CODE : // intermed - 150
575 // this response is ok
576 return true;
577 case FTPResponse.DATA_CONNECTION_ALREADY_OPENED_CODE : // intermed - 125
578 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
579 case FTPResponse.CAN_T_OPEN_DATA_CONNECTION_CODE : // failure - 425
580 case FTPResponse.DATA_CONNECTION_ABORTED_CODE : // failure - 426
581 case FTPResponse.TRANSIENT_UNAVAILABLE_FILE_CODE : // failure - 450
582 case FTPResponse.TRANSIENT_LOCAL_PROCESSING_ERROR_CODE : // failure - 451
583 case FTPResponse.TRANSIENT_INSUFFICIENT_STORAGE_SPACE_CODE : // failure - 452
584 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
585 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
586 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
587 case FTPResponse.NEED_ACCOUNT_FOR_STORING_FILES_CODE : // failure - 532
588 case FTPResponse.PAGE_TYPE_UNKNOWN_CODE : // failure - 551
589 case FTPResponse.EXCEEDED_STORAGE_ALLOCATION_CODE : // failure - 552
590 case FTPResponse.FINE_NAME_NOT_ALLOWED_CODE : // failure - 553
591 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
592 default :
593 throw FTPException.createInvalidResponseException(this, response.getCode(), "STOR");
594 }
595 }
596
597 /**
598 * Checks if the <code>response</code> is the last that
599 * one has to expect for the <code>command</code>.
600 *
601 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
602 * @param response response from server to check.
603 * @return <code>true</code> if the <code>response</code> is
604 * the last to expect from server for the STOU command.
605 * @exception FTPException <code>response</code> is not a valid answer
606 * for the <code>command</code>.
607 * @since v1.0
608 */
609 protected boolean isSTOUCommandCompleted ( FTPResponse response ) throws FTPException {
610 switch ( response.getCode() ) {
611 case FTPResponse.RESTART_MARKER_RESPONSE_CODE : // intermed - 110
612 // this response is ok, but more replies to come
613 return false;
614 case FTPResponse.DATA_CONNECTION_ABOUT_TO_BE_OPENED_CODE : // intermed - 150
615 // this response is ok
616 return true;
617 case FTPResponse.DATA_CONNECTION_ALREADY_OPENED_CODE : // intermed - 125
618 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
619 case FTPResponse.CAN_T_OPEN_DATA_CONNECTION_CODE : // failure - 425
620 case FTPResponse.DATA_CONNECTION_ABORTED_CODE : // failure - 426
621 case FTPResponse.TRANSIENT_UNAVAILABLE_FILE_CODE : // failure - 450
622 case FTPResponse.TRANSIENT_LOCAL_PROCESSING_ERROR_CODE : // failure - 451
623 case FTPResponse.TRANSIENT_INSUFFICIENT_STORAGE_SPACE_CODE : // failure - 452
624 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
625 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
626 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
627 case FTPResponse.NEED_ACCOUNT_FOR_STORING_FILES_CODE : // failure - 532
628 case FTPResponse.PAGE_TYPE_UNKNOWN_CODE : // failure - 551
629 case FTPResponse.EXCEEDED_STORAGE_ALLOCATION_CODE : // failure - 552
630 case FTPResponse.FINE_NAME_NOT_ALLOWED_CODE : // failure - 553
631 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
632 default :
633 throw FTPException.createInvalidResponseException(this, response.getCode(), "STOU");
634 }
635 }
636
637 /**
638 * Checks if the <code>response</code> is the last that
639 * one has to expect for the <code>command</code>.
640 *
641 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
642 * @param response response from server to check.
643 * @return <code>true</code> if the <code>response</code> is
644 * the last to expect from server for the APPE command.
645 * @exception FTPException <code>response</code> is not a valid answer
646 * for the <code>command</code>.
647 * @since v1.0
648 */
649 protected boolean isAPPECommandCompleted ( FTPResponse response ) throws FTPException {
650 switch ( response.getCode() ) {
651 case FTPResponse.RESTART_MARKER_RESPONSE_CODE : // intermed - 110
652 // this response is ok, but more replies to come
653 return false;
654 case FTPResponse.DATA_CONNECTION_ABOUT_TO_BE_OPENED_CODE : // intermed - 150
655 // this response is ok
656 return true;
657 case FTPResponse.DATA_CONNECTION_ALREADY_OPENED_CODE : // intermed - 125
658 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
659 case FTPResponse.CAN_T_OPEN_DATA_CONNECTION_CODE : // failure - 425
660 case FTPResponse.DATA_CONNECTION_ABORTED_CODE : // failure - 426
661 case FTPResponse.TRANSIENT_UNAVAILABLE_FILE_CODE : // failure - 450
662 case FTPResponse.TRANSIENT_LOCAL_PROCESSING_ERROR_CODE : // failure - 451
663 case FTPResponse.TRANSIENT_INSUFFICIENT_STORAGE_SPACE_CODE : // failure - 452
664 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
665 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
666 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
667 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
668 case FTPResponse.NEED_ACCOUNT_FOR_STORING_FILES_CODE : // failure - 532
669 case FTPResponse.PERMANENTLY_UNAVAILABLE_FILE_CODE : // failure - 550
670 case FTPResponse.PAGE_TYPE_UNKNOWN_CODE : // failure - 551
671 case FTPResponse.EXCEEDED_STORAGE_ALLOCATION_CODE : // failure - 552
672 case FTPResponse.FINE_NAME_NOT_ALLOWED_CODE : // failure - 553
673 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
674 default :
675 throw FTPException.createInvalidResponseException(this, response.getCode(), "APPE");
676 }
677 }
678
679 /**
680 * Checks if the <code>response</code> is the last that
681 * one has to expect for the <code>command</code>.
682 *
683 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
684 * @param response response from server to check.
685 * @return <code>true</code> if the <code>response</code> is
686 * the last to expect from server for the ALLO command.
687 * @exception FTPException <code>response</code> is not a valid answer
688 * for the <code>command</code>.
689 * @since v1.0
690 */
691 protected boolean isALLOCommandCompleted ( FTPResponse response ) throws FTPException {
692 switch ( response.getCode() ) {
693 case FTPResponse.POSITIVE_COMPLETION_RESPONSE_CODE : // success - 200
694 case FTPResponse.SUPERFLOUS_COMMAND_CODE : // success - 202
695 // this response is ok
696 return true;
697 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
698 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
699 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
700 case FTPResponse.COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER_CODE : // failure - 504
701 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
702 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
703 default :
704 throw FTPException.createInvalidResponseException(this, response.getCode(), "ALLO");
705 }
706 }
707
708 /**
709 * Checks if the <code>response</code> is the last that
710 * one has to expect for the <code>command</code>.
711 *
712 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
713 * @param response response from server to check.
714 * @return <code>true</code> if the <code>response</code> is
715 * the last to expect from server for the REST command.
716 * @exception FTPException <code>response</code> is not a valid answer
717 * for the <code>command</code>.
718 * @since v1.0
719 */
720 protected boolean isRESTCommandCompleted ( FTPResponse response ) throws FTPException {
721 switch ( response.getCode() ) {
722 case FTPResponse.REQUESTED_FILE_ACTION_PENDING_CODE : // intermed - 350
723 // this response is ok
724 return true;
725 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
726 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
727 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
728 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
729 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
730 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
731 default :
732 throw FTPException.createInvalidResponseException(this, response.getCode(), "REST");
733 }
734 }
735
736 /**
737 * Checks if the <code>response</code> is the last that
738 * one has to expect for the <code>command</code>.
739 *
740 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
741 * @param response response from server to check.
742 * @return <code>true</code> if the <code>response</code> is
743 * the last to expect from server for the RNFR command.
744 * @exception FTPException <code>response</code> is not a valid answer
745 * for the <code>command</code>.
746 * @since v1.0
747 */
748 protected boolean isRNFRCommandCompleted ( FTPResponse response ) throws FTPException {
749 switch ( response.getCode() ) {
750 case FTPResponse.REQUESTED_FILE_ACTION_PENDING_CODE : // intermed - 350
751 // this response is ok
752 return true;
753 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
754 case FTPResponse.TRANSIENT_UNAVAILABLE_FILE_CODE : // failure - 450
755 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
756 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
757 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
758 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
759 case FTPResponse.PERMANENTLY_UNAVAILABLE_FILE_CODE : // failure - 550
760 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
761 default :
762 throw FTPException.createInvalidResponseException(this, response.getCode(), "RNFR");
763 }
764 }
765
766 /**
767 * Checks if the <code>response</code> is the last that
768 * one has to expect for the <code>command</code>.
769 *
770 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
771 * @param response response from server to check.
772 * @return <code>true</code> if the <code>response</code> is
773 * the last to expect from server for the RNTO command.
774 * @exception FTPException <code>response</code> is not a valid answer
775 * for the <code>command</code>.
776 * @since v1.0
777 */
778 protected boolean isRNTOCommandCompleted ( FTPResponse response ) throws FTPException {
779 switch ( response.getCode() ) {
780 case FTPResponse.REQUESTED_FILE_ACTION_OK_CODE : // success - 250
781 // this response is ok
782 return true;
783 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
784 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
785 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
786 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
787 case FTPResponse.BAD_COMMAND_SEQUENCE_CODE : // failure - 503
788 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
789 case FTPResponse.NEED_ACCOUNT_FOR_STORING_FILES_CODE : // failure - 532
790 case FTPResponse.FINE_NAME_NOT_ALLOWED_CODE : // failure - 553
791 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
792 default :
793 throw FTPException.createInvalidResponseException(this, response.getCode(), "RNTO");
794 }
795 }
796
797 /**
798 * Checks if the <code>response</code> is the last that
799 * one has to expect for the <code>command</code>.
800 *
801 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
802 * @param response response from server to check.
803 * @return <code>true</code> if the <code>response</code> is
804 * the last to expect from server for the ABOR command.
805 * @exception FTPException <code>response</code> is not a valid answer
806 * for the <code>command</code>.
807 * @since v1.0
808 */
809 protected boolean isABORCommandCompleted ( FTPResponse response ) throws FTPException {
810 switch ( response.getCode() ) {
811 case FTPResponse.DATA_CONNECTION_OPENED_CODE : // success - 225
812 case FTPResponse.DATA_CONNECTION_CLOSED_CODE : // success - 226
813 // this response is ok
814 return true;
815 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
816 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
817 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
818 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
819 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
820 default :
821 throw FTPException.createInvalidResponseException(this, response.getCode(), "ABOR");
822 }
823 }
824
825 /**
826 * Checks if the <code>response</code> is the last that
827 * one has to expect for the <code>command</code>.
828 *
829 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
830 * @param response response from server to check.
831 * @return <code>true</code> if the <code>response</code> is
832 * the last to expect from server for the DELE command.
833 * @exception FTPException <code>response</code> is not a valid answer
834 * for the <code>command</code>.
835 * @since v1.0
836 */
837 protected boolean isDELECommandCompleted ( FTPResponse response ) throws FTPException {
838 switch ( response.getCode() ) {
839 case FTPResponse.REQUESTED_FILE_ACTION_OK_CODE : // success - 250
840 // this response is ok
841 return true;
842 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
843 case FTPResponse.TRANSIENT_UNAVAILABLE_FILE_CODE : // failure - 450
844 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
845 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
846 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
847 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
848 case FTPResponse.PERMANENTLY_UNAVAILABLE_FILE_CODE : // failure - 550
849 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
850 default :
851 throw FTPException.createInvalidResponseException(this, response.getCode(), "DELE");
852 }
853 }
854
855 /**
856 * Checks if the <code>response</code> is the last that
857 * one has to expect for the <code>command</code>.
858 *
859 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
860 * @param response response from server to check.
861 * @return <code>true</code> if the <code>response</code> is
862 * the last to expect from server for the RMD command.
863 * @exception FTPException <code>response</code> is not a valid answer
864 * for the <code>command</code>.
865 * @since v1.0
866 */
867 protected boolean isRMDCommandCompleted ( FTPResponse response ) throws FTPException {
868 switch ( response.getCode() ) {
869 case FTPResponse.REQUESTED_FILE_ACTION_OK_CODE : // success - 250
870 // this response is ok
871 return true;
872 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
873 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
874 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
875 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
876 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
877 case FTPResponse.PERMANENTLY_UNAVAILABLE_FILE_CODE : // failure - 550
878 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
879 default :
880 throw FTPException.createInvalidResponseException(this, response.getCode(), "RMD");
881 }
882 }
883
884 /**
885 * Checks if the <code>response</code> is the last that
886 * one has to expect for the <code>command</code>.
887 *
888 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
889 * @param response response from server to check.
890 * @return <code>true</code> if the <code>response</code> is
891 * the last to expect from server for the MKD command.
892 * @exception FTPException <code>response</code> is not a valid answer
893 * for the <code>command</code>.
894 * @since v1.0
895 */
896 protected boolean isMKDCommandCompleted ( FTPResponse response ) throws FTPException {
897 switch ( response.getCode() ) {
898 case FTPResponse.PATHNAME_CREATED_CODE : // success - 257
899 // this response is ok
900 return true;
901 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
902 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
903 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
904 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
905 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
906 case FTPResponse.PERMANENTLY_UNAVAILABLE_FILE_CODE : // failure - 550
907 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
908 default :
909 throw FTPException.createInvalidResponseException(this, response.getCode(), "MKD");
910 }
911 }
912
913 /**
914 * Checks if the <code>response</code> is the last that
915 * one has to expect for the <code>command</code>.
916 *
917 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
918 * @param response response from server to check.
919 * @return <code>true</code> if the <code>response</code> is
920 * the last to expect from server for the PWD command.
921 * @exception FTPException <code>response</code> is not a valid answer
922 * for the <code>command</code>.
923 * @since v1.0
924 */
925 protected boolean isPWDCommandCompleted ( FTPResponse response ) throws FTPException {
926 switch ( response.getCode() ) {
927 case FTPResponse.PATHNAME_CREATED_CODE : // success - 257
928 // this response is ok
929 return true;
930 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
931 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
932 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
933 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
934 case FTPResponse.PERMANENTLY_UNAVAILABLE_FILE_CODE : // failure - 550
935 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
936 default :
937 throw FTPException.createInvalidResponseException(this, response.getCode(), "PWD");
938 }
939 }
940
941 /**
942 * Checks if the <code>response</code> is the last that
943 * one has to expect for the <code>command</code>.
944 *
945 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
946 * @param response response from server to check.
947 * @return <code>true</code> if the <code>response</code> is
948 * the last to expect from server for the LIST command.
949 * @exception FTPException <code>response</code> is not a valid answer
950 * for the <code>command</code>.
951 * @since v1.0
952 */
953 protected boolean isLISTCommandCompleted ( FTPResponse response ) throws FTPException {
954 switch ( response.getCode() ) {
955 case FTPResponse.DATA_CONNECTION_CLOSED_CODE : // success - 226
956 case FTPResponse.REQUESTED_FILE_ACTION_OK_CODE : // success - 250
957 // this response is ok, but more to come
958 return false;
959 case FTPResponse.DATA_CONNECTION_ABOUT_TO_BE_OPENED_CODE : // intermed - 150
960 // this response is ok
961 return true;
962 case FTPResponse.DATA_CONNECTION_ALREADY_OPENED_CODE : // intermed - 125
963 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
964 case FTPResponse.CAN_T_OPEN_DATA_CONNECTION_CODE : // failure - 425
965 case FTPResponse.DATA_CONNECTION_ABORTED_CODE : // failure - 426
966 case FTPResponse.TRANSIENT_UNAVAILABLE_FILE_CODE : // failure - 450
967 case FTPResponse.TRANSIENT_LOCAL_PROCESSING_ERROR_CODE : // failure - 451
968 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
969 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
970 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
971 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
972 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
973 default :
974 throw FTPException.createInvalidResponseException(this, response.getCode(), "LIST");
975 }
976 }
977
978 /**
979 * Checks if the <code>response</code> is the last that
980 * one has to expect for the <code>command</code>.
981 *
982 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
983 * @param response response from server to check.
984 * @return <code>true</code> if the <code>response</code> is
985 * the last to expect from server for the NLST command.
986 * @exception FTPException <code>response</code> is not a valid answer
987 * for the <code>command</code>.
988 * @since v1.0
989 */
990 protected boolean isNLSTCommandCompleted ( FTPResponse response ) throws FTPException {
991 switch ( response.getCode() ) {
992 case FTPResponse.DATA_CONNECTION_CLOSED_CODE : // success - 226
993 case FTPResponse.REQUESTED_FILE_ACTION_OK_CODE : // success - 250
994 // this response is ok, but more to come
995 return false;
996 case FTPResponse.DATA_CONNECTION_ALREADY_OPENED_CODE : // intermed - 125
997 case FTPResponse.DATA_CONNECTION_ABOUT_TO_BE_OPENED_CODE : // intermed - 150
998 // this response is ok
999 return true;
1000 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
1001 case FTPResponse.CAN_T_OPEN_DATA_CONNECTION_CODE : // failure - 425
1002 case FTPResponse.DATA_CONNECTION_ABORTED_CODE : // failure - 426
1003 case FTPResponse.TRANSIENT_UNAVAILABLE_FILE_CODE : // failure - 450
1004 case FTPResponse.TRANSIENT_LOCAL_PROCESSING_ERROR_CODE : // failure - 451
1005 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
1006 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
1007 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
1008 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
1009 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
1010 default :
1011 throw FTPException.createInvalidResponseException(this, response.getCode(), "NLST");
1012 }
1013 }
1014
1015 /**
1016 * Checks if the <code>response</code> is the last that
1017 * one has to expect for the <code>command</code>.
1018 *
1019 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
1020 * @param response response from server to check.
1021 * @return <code>true</code> if the <code>response</code> is
1022 * the last to expect from server for the SITE command.
1023 * @exception FTPException <code>response</code> is not a valid answer
1024 * for the <code>command</code>.
1025 * @since v1.0
1026 */
1027 protected boolean isSITECommandCompleted ( FTPResponse response ) throws FTPException {
1028 switch ( response.getCode() ) {
1029 case FTPResponse.POSITIVE_COMPLETION_RESPONSE_CODE : // success - 200
1030 case FTPResponse.SUPERFLOUS_COMMAND_CODE : // success - 202
1031 // this response is ok
1032 return true;
1033 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
1034 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
1035 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
1036 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
1037 default :
1038 throw FTPException.createInvalidResponseException(this, response.getCode(), "SITE");
1039 }
1040 }
1041
1042 /**
1043 * Checks if the <code>response</code> is the last that
1044 * one has to expect for the <code>command</code>.
1045 *
1046 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
1047 * @param response response from server to check.
1048 * @return <code>true</code> if the <code>response</code> is
1049 * the last to expect from server for the SYST command.
1050 * @exception FTPException <code>response</code> is not a valid answer
1051 * for the <code>command</code>.
1052 * @since v1.0
1053 */
1054 protected boolean isSYSTCommandCompleted ( FTPResponse response ) throws FTPException {
1055 switch ( response.getCode() ) {
1056 case FTPResponse.SYSTEM_TYPE_NAME_CODE : // success - 215
1057 // this response is ok
1058 return true;
1059 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
1060 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
1061 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
1062 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
1063 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
1064 default :
1065 throw FTPException.createInvalidResponseException(this, response.getCode(), "SYST");
1066 }
1067 }
1068
1069 /**
1070 * Checks if the <code>response</code> is the last that
1071 * one has to expect for the <code>command</code>.
1072 *
1073 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
1074 * @param response response from server to check.
1075 * @return <code>true</code> if the <code>response</code> is
1076 * the last to expect from server for the STAT command.
1077 * @exception FTPException <code>response</code> is not a valid answer
1078 * for the <code>command</code>.
1079 * @since v1.0
1080 */
1081 protected boolean isSTATCommandCompleted ( FTPResponse response ) throws FTPException {
1082 switch ( response.getCode() ) {
1083 case FTPResponse.SYSTEM_STATUS_OR_HELP_RESPONSE_CODE : // success - 211
1084 case FTPResponse.DIRECTORY_STATUS_CODE : // success - 212
1085 case FTPResponse.FILE_STATUS_CODE : // success - 213
1086 // this response is ok
1087 return true;
1088 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
1089 case FTPResponse.TRANSIENT_UNAVAILABLE_FILE_CODE : // failure - 450
1090 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
1091 case FTPResponse.SYNTAX_ERROR_IN_ARGUMENTS_CODE : // failure - 501
1092 case FTPResponse.COMMAND_NOT_IMPLEMENTED_CODE : // failure - 502
1093 case FTPResponse.NOT_LOGGED_IN_CODE : // failure - 530
1094 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
1095 default :
1096 throw FTPException.createInvalidResponseException(this, response.getCode(), "STAT");
1097 }
1098 }
1099
1100 /**
1101 * Checks if the <code>response</code> is the last that
1102 * one has to expect for the <code>command</code>.
1103 *
1104 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
1105 * @param response response from server to check.
1106 * @return <code>true</code> if the <code>response</code> is
1107 * the last to expect from server for the HELP command.
1108 * @exception FTPException <code>response</code> is not a valid answer
1109 * for the <code>command</code>.
1110 * @since v1.0
1111 */
1112/* FIXME: does it belong here ?!
1113 protected boolean isHELPCommandCompleted ( FTPResponse response ) throws FTPException {
1114 switch ( response.getCode() ) {
1115 default :
1116 throw FTPException.createInvalidResponseException(this, response.getCode(), "HELP");
1117 }
1118 }
1119*/
1120
1121 /**
1122 * Checks if the <code>response</code> is the last that
1123 * one has to expect for the <code>command</code>.
1124 *
1125 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
1126 * @param response response from server to check.
1127 * @return <code>true</code> if the <code>response</code> is
1128 * the last to expect from server for the NOOP command.
1129 * @exception FTPException <code>response</code> is not a valid answer
1130 * for the <code>command</code>.
1131 * @since v1.0
1132 */
1133 protected boolean isNOOPCommandCompleted ( FTPResponse response ) throws FTPException {
1134 switch ( response.getCode() ) {
1135 case FTPResponse.POSITIVE_COMPLETION_RESPONSE_CODE : // success - 200
1136 // this response is ok
1137 return true;
1138 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
1139 case FTPResponse.PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE : // failure - 500
1140 throw new FTPException(this, response.getCode(), response.getOriginalMessage());
1141 default :
1142 throw FTPException.createInvalidResponseException(this, response.getCode(), "NOOP");
1143 }
1144 }
1145
1146
1147
1148
1149
1150 /**
1151 * Checks if the <code>response</code> is the last that
1152 * one has to expect to end a <code>command</code> that
1153 * required a data connection setup and destruction.
1154 *
1155 * This method only applies to:
1156 * <ul>
1157 * <li><code>org.finj.FTPCommand.APPEND_WITH_CREATE</code></li>
1158 * <li><code>org.finj.FTPCommand.NAME_LIST</code></li>
1159 * <li><code>org.finj.FTPCommand.STORE_FILE</code></li>
1160 * <li><code>org.finj.FTPCommand.STORE_UNIQUE_FILE</code> FIXME:check that!</li>
1161 * </ul>
1162 *
1163 * and should be called AFTER a call to
1164 * <code>isCommandCompleted(org.finj.FTPCommand, org.finj.FTPResponse)</code>
1165 * which will be the one triggering the command execution and
1166 * data connection opening.
1167 *
1168 * @param command <code>org.finj.FTPCommand</code> sent to the server.
1169 * @param response <code>org.finj.FTPResponse</code> returned by the server.
1170 * @return <code>true</code> if the <code>response</code> is the last
1171 * to expect from server for the <code>command</code>.
1172 * @exception FTPException <code>response</code> is not a valid answer
1173 * for the <code>command</code>.
1174 * @since v1.0
1175 */
1176 public boolean isPostCommandCompleted ( FTPCommand command, FTPResponse response ) throws FTPException {
1177 switch ( command.getCode() ) {
1178 case FTPCommand.APPEND_WITH_CREATE :
1179 return isPostAPPECommandCompleted(response);
1180 case FTPCommand.LIST :
1181 return isPostLISTCommandCompleted(response);
1182 case FTPCommand.NAME_LIST :
1183 return isPostNLSTCommandCompleted(response);
1184 case FTPCommand.RETRIEVE :
1185 return isPostRETRCommandCompleted(response);
1186 case FTPCommand.STORE_FILE :
1187 return isPostSTORCommandCompleted(response);
1188 case FTPCommand.STORE_UNIQUE_FILE :
1189 return isPostSTOUCommandCompleted(response);
1190 }
1191 throw new FTPException(this, command.getCode(), " is not a valid FTP command");
1192 }
1193
1194 /**
1195 * Checks if the <code>response</code> is the last that
1196 * one has to expect to end the <code>command</code> that
1197 * required a data connection setup and destruction.
1198 *
1199 * @see "RFC959-5:4:'Sequencing of Commands and Replies'"
1200 * @param response response from server to check.
1201 * @return <code>true</code> if the <code>response</code> is the last
1202 * to expect from server for the APPE.
1203 * @exception FTPException <code>response</code> is not a valid answer
1204 * for the <code>command</code>.
1205 * @since v1.0
1206 */
1207 protected boolean isPostAPPECommandCompleted ( FTPResponse response ) throws FTPException {
1208 switch ( response.getCode() ) {
1209 case FTPResponse.DATA_CONNECTION_CLOSED_CODE : // success - 226
1210 case FTPResponse.REQUESTED_FILE_ACTION_OK_CODE : // success - 250
1211 // this response is ok
1212 return true;
1213 // FIXME : some of those codes might be useless at this position
1214 case FTPResponse.DATA_CONNECTION_ALREADY_OPENED_CODE : // intermed - 125
1215 case FTPResponse.SERVICE_NOT_AVAILABLE_CODE : // failure - 421
1216 case FTPResponse.CAN_T_OPEN_DATA_CONNECTION_CODE : // failure - 425
1217 case FTPResponse.DATA_CONNECTION_ABORTED_CODE : // failure - 426
1218 case FTPResponse.TRANSIENT_UNAVAILABLE_FILE_CODE : // failure - 450
1219 case FTPResponse.TRANSIENT_LOCAL_PROCESSING_ERROR_CODE :