java.lang.Object
org.miaixz.bus.extra.ftp.AbstractFtp
- All Implemented Interfaces:
Closeable,AutoCloseable,Ftp
- Direct Known Subclasses:
CommonsFtp,JschSftp,SshjSftp
Abstract base class for FTP operations. This class provides common utility methods and a basic structure for FTP
client implementations, handling tasks like path existence checks, directory creation, and robust file downloading.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FtpConfigThe FTP configuration settings used by this client.Fields inherited from interface org.miaixz.bus.extra.ftp.Ftp
DEFAULT_CHARSET -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractFtp(FtpConfig config) Constructs anAbstractFtpinstance with the specified FTP configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidDownloads a file from the remote server to a local file, ensuring atomicity by using a temporary file.booleanChecks if a file or directory exists at the specified path on the remote server.Retrieves the FTP configuration associated with this FTP client instance.voidCreates the specified folder and its parent directories on the remote server.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.miaixz.bus.extra.ftp.Ftp
cd, delDir, delFile, download, getFileStream, isDir, ls, mkdir, pwd, reconnectIfTimeout, recursiveDownloadFolder, rename, toParent, uploadFile
-
Field Details
-
ftpConfig
The FTP configuration settings used by this client.
-
-
Constructor Details
-
AbstractFtp
Constructs anAbstractFtpinstance with the specified FTP configuration.- Parameters:
config- TheFtpConfigcontaining connection and operational settings.
-
-
Method Details
-
getConfig
Retrieves the FTP configuration associated with this FTP client instance. -
exist
Checks if a file or directory exists at the specified path on the remote server. This method handles both directory and file existence checks, including special cases for empty paths, paths ending with file separators, and special directory names like "." and "..". -
mkDirs
Creates the specified folder and its parent directories on the remote server. This method navigates through the path components, creating directories as needed. After creation, the working directory is restored to its original state. -
download
Downloads a file from the remote server to a local file, ensuring atomicity by using a temporary file. The principle of this method is to first download the file to a temporary file in the same directory as the target file. Once the download is complete, the temporary file is renamed to the final target name. This prevents incomplete files from being left behind in case of download errors.- Parameters:
path- The file path on the remote server.outFile- The localFileor directory where the downloaded file should be saved. If it's a directory, the server's filename will be used.tempFileSuffix- The suffix for temporary files, e.g., ".temp". If blank, defaults to ".temp".- Throws:
org.miaixz.bus.core.lang.exception.InternalException- if an error occurs during download or file operations (e.g., I/O errors, renaming issues).
-