View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2.provider.ftp;
18  
19  import java.io.IOException;
20  import java.io.InputStream;
21  import java.io.OutputStream;
22  import java.time.Instant;
23  
24  import org.apache.commons.net.ftp.FTPFile;
25  import org.apache.commons.net.ftp.FTPReply;
26  import org.apache.commons.vfs2.FileSystemException;
27  
28  /**
29   * What VFS expects from an FTP client to provide.
30   */
31  public interface FtpClient {
32  
33      boolean abort() throws IOException;
34  
35      OutputStream appendFileStream(String relPath) throws IOException;
36  
37      boolean completePendingCommand() throws IOException;
38  
39      boolean deleteFile(String relPath) throws IOException;
40  
41      void disconnect() throws IOException;
42  
43      default int getReplyCode() throws IOException {
44          return FTPReply.COMMAND_OK;
45      }
46  
47      String getReplyString() throws IOException;
48  
49      /**
50       * Queries the server for a supported feature.
51       *
52       * @param feature the name of the feature, converted to upper case.
53       * @return {@code true} if the feature is present, {@code false} if the feature is not present or the FTP command
54       *         failed.
55       *
56       * @throws IOException on error
57       * @since 2.8.0
58       */
59      boolean hasFeature(final String feature) throws IOException;
60  
61      boolean isConnected() throws FileSystemException;
62  
63      // This interface should not leak Apache Commons NET types like FTPFile
64      FTPFile[] listFiles(String relPath) throws IOException;
65  
66      boolean makeDirectory(String relPath) throws IOException;
67  
68      /**
69       * Sends the MDTM command to get a file's date and time information after file transfer. It is typically more
70       * accurate than the {@code "LIST"} command response. Time values are always represented in UTC (GMT), and in the
71       * Gregorian calendar regardless of what calendar may have been in use at the date and time the file was last
72       * modified.
73       * <p>
74       * NOTE: not all remote FTP servers support {@code MDTM}.
75       * </p>
76       *
77       * @param relPath The relative path of the file object to execute {@code MDTM} command against
78       * @return new {@code Instant} object containing the {@code MDTM} timestamp.
79       * @throws IOException If the underlying FTP client encountered an error.
80       * @since 2.8.0
81       */
82      default Instant mdtmInstant(final String relPath) throws IOException {
83          return null;
84      }
85  
86      boolean removeDirectory(String relPath) throws IOException;
87  
88      boolean rename(String oldName, String newName) throws IOException;
89  
90      InputStream retrieveFileStream(String relPath) throws IOException;
91  
92      default InputStream retrieveFileStream(final String relPath, final int bufferSize) throws IOException {
93          // Backward compatibility: no buffer size.
94          return retrieveFileStream(relPath);
95      }
96  
97      InputStream retrieveFileStream(String relPath, long restartOffset) throws IOException;
98  
99      default void setBufferSize(final int bufferSize) throws FileSystemException {
100         // Backward compatibility: do nothing.
101     }
102 
103     OutputStream storeFileStream(String relPath) throws IOException;
104 
105 }