|
24 | 24 | import org.apache.commons.logging.Log; |
25 | 25 | import org.apache.commons.logging.LogFactory; |
26 | 26 | import org.apache.commons.net.ftp.FTPClient; |
| 27 | +import org.apache.commons.net.ftp.FTPConnectionClosedException; |
27 | 28 | import org.apache.commons.net.ftp.FTPFile; |
28 | 29 | import org.apache.commons.net.ftp.FTPReply; |
29 | 30 | import org.apache.commons.vfs2.FileSystemException; |
@@ -94,17 +95,14 @@ public boolean completePendingCommand() throws IOException { |
94 | 95 | if (ftpClient != null) { |
95 | 96 | return getFtpClient().completePendingCommand(); |
96 | 97 | } |
97 | | - |
98 | 98 | return true; |
99 | 99 | } |
100 | 100 |
|
101 | 101 | private FTPClient createClient() throws FileSystemException { |
102 | 102 | final GenericFileName rootName = getRoot(); |
103 | | - |
104 | 103 | UserAuthenticationData authData = null; |
105 | 104 | try { |
106 | 105 | authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, FtpFileProvider.AUTHENTICATOR_TYPES); |
107 | | - |
108 | 106 | return createClient(rootName, authData); |
109 | 107 | } finally { |
110 | 108 | UserAuthenticatorUtils.cleanup(authData); |
@@ -168,7 +166,6 @@ private FTPClient getFtpClient() throws FileSystemException { |
168 | 166 | if (ftpClient == null) { |
169 | 167 | ftpClient = createClient(); |
170 | 168 | } |
171 | | - |
172 | 169 | return ftpClient; |
173 | 170 | } |
174 | 171 |
|
@@ -328,6 +325,32 @@ public InputStream retrieveFileStream(final String relPath, final long restartOf |
328 | 325 | } |
329 | 326 | } |
330 | 327 |
|
| 328 | + /** |
| 329 | + * A convenience method to send the FTP OPTS command to the server, receive the reply, and return the reply code. |
| 330 | + * <p> |
| 331 | + * FTP request Syntax: |
| 332 | + * </p> |
| 333 | + * <pre>{@code |
| 334 | + * opts = opts-cmd SP command-name |
| 335 | + * [ SP command-options ] CRLF |
| 336 | + * opts-cmd = "opts" |
| 337 | + * command-name = <any FTP command which allows option setting> |
| 338 | + * command-options = <format specified by individual FTP command> |
| 339 | + * }</pre> |
| 340 | + * @param commandName The OPTS command name. |
| 341 | + * @param commandOptions The OPTS command options. |
| 342 | + * @return The reply code received from the server. |
| 343 | + * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason |
| 344 | + * causing the server to send FTP reply code 421. This exception may be caught either as an IOException or |
| 345 | + * independently as itself. |
| 346 | + * @throws IOException If an I/O error occurs while either sending the command or receiving the server reply. |
| 347 | + */ |
| 348 | + public int sendOptions(final String commandName, String commandOptions) throws IOException { |
| 349 | + // Commons Net 3.12.0 |
| 350 | + // return getFtpClient().opts(commandName, commandOptions); |
| 351 | + return getFtpClient().sendCommand("OPTS", commandName + ' ' + commandOptions); |
| 352 | + } |
| 353 | + |
331 | 354 | @Override |
332 | 355 | public void setBufferSize(final int bufferSize) throws FileSystemException { |
333 | 356 | getFtpClient().setBufferSize(bufferSize); |
|
0 commit comments