1 package ch
.cyberduck
.core
.ftp
;
4 * Copyright (c) 2002-2013 David Kocher. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to feedback@cyberduck.ch
20 import ch
.cyberduck
.core
.AbstractExceptionMappingService
;
21 import ch
.cyberduck
.core
.DefaultIOExceptionMappingService
;
22 import ch
.cyberduck
.core
.exception
.AccessDeniedException
;
23 import ch
.cyberduck
.core
.exception
.BackgroundException
;
24 import ch
.cyberduck
.core
.exception
.ConnectionRefusedException
;
25 import ch
.cyberduck
.core
.exception
.InteroperabilityException
;
26 import ch
.cyberduck
.core
.exception
.LoginFailureException
;
27 import ch
.cyberduck
.core
.exception
.NotfoundException
;
28 import ch
.cyberduck
.core
.exception
.QuotaException
;
30 import org
.apache
.commons
.net
.MalformedServerReplyException
;
31 import org
.apache
.commons
.net
.ftp
.FTPConnectionClosedException
;
32 import org
.apache
.commons
.net
.ftp
.FTPReply
;
34 import java
.io
.IOException
;
39 public class FTPExceptionMappingService
extends AbstractExceptionMappingService
<IOException
> {
42 public BackgroundException
map(final IOException e
) {
43 final StringBuilder buffer
= new StringBuilder();
44 this.append(buffer
, e
.getMessage());
45 if(e
instanceof FTPConnectionClosedException
) {
46 return new ConnectionRefusedException(buffer
.toString(), e
);
48 if(e
instanceof FTPException
) {
49 return this.handle((FTPException
) e
, buffer
);
51 if(e
instanceof MalformedServerReplyException
) {
52 return new InteroperabilityException(buffer
.toString(), e
);
54 return new DefaultIOExceptionMappingService().map(e
);
57 private BackgroundException
handle(final FTPException e
, final StringBuilder buffer
) {
58 final int status
= e
.getCode();
60 case FTPReply
.INSUFFICIENT_STORAGE
:
61 case FTPReply
.STORAGE_ALLOCATION_EXCEEDED
:
62 return new QuotaException(buffer
.toString(), e
);
63 case FTPReply
.NOT_LOGGED_IN
:
64 return new LoginFailureException(buffer
.toString(), e
);
65 case FTPReply
.FAILED_SECURITY_CHECK
:
66 case FTPReply
.DENIED_FOR_POLICY_REASONS
:
67 case FTPReply
.NEED_ACCOUNT
:
68 case FTPReply
.NEED_ACCOUNT_FOR_STORING_FILES
:
69 case FTPReply
.FILE_NAME_NOT_ALLOWED
:
70 return new AccessDeniedException(buffer
.toString(), e
);
71 case FTPReply
.UNAVAILABLE_RESOURCE
:
72 case FTPReply
.FILE_UNAVAILABLE
:
73 // Requested action not taken. File unavailable (e.g., file not found, no access)
74 return new NotfoundException(buffer
.toString(), e
);
76 return new InteroperabilityException(buffer
.toString(), e
);