public interface Ftp extends Closeable
Modifier and Type | Field and Description |
---|---|
static Charset |
DEFAULT_CHARSET
默认编码
|
Modifier and Type | Method and Description |
---|---|
boolean |
cd(String directory)
打开指定目录,具体逻辑取决于实现,例如在FTP中,进入失败返回
false , SFTP中则抛出异常 |
boolean |
delDir(String dirPath)
删除文件夹及其文件夹下的所有文件
|
boolean |
delFile(String path)
删除指定目录下的指定文件
|
void |
download(String path,
File outFile)
下载文件
|
boolean |
exist(String path)
文件或目录是否存在
提供路径为空则返回 false
提供路径非目录但是以'/'或'\'结尾返回false
文件名是'.' |
FtpConfig |
getConfig()
获取FTP配置
|
InputStream |
getFileStream(String path)
读取FTP服务器上的文件为输入流
|
default boolean |
isDir(String dir)
判断给定路径是否为目录
|
List<String> |
ls(String path)
遍历某个目录下所有文件和目录,不会递归遍历
|
boolean |
mkdir(String dir)
在当前远程目录(工作目录)下创建新的目录
|
void |
mkDirs(String dir)
创建指定文件夹及其父目录,从根目录开始创建,创建完成后回到默认的工作目录
|
String |
pwd()
远程当前目录(工作目录)
|
Ftp |
reconnectIfTimeout()
如果连接超时的话,重新进行连接
|
void |
recursiveDownloadFolder(String sourcePath,
File destDir)
递归下载FTP服务器上文件到本地(文件目录和服务器同步), 服务器上有新文件会覆盖本地文件
|
default boolean |
toParent()
打开上级目录
|
boolean |
uploadFile(String destPath,
File file)
将本地文件上传到目标服务器,目标文件名为destPath,若destPath为目录,则目标文件名将与file文件名相同。
|
static final Charset DEFAULT_CHARSET
FtpConfig getConfig()
Ftp reconnectIfTimeout()
String pwd()
boolean cd(String directory)
false
, SFTP中则抛出异常directory
- directorydefault boolean toParent()
boolean exist(String path)
false
false
false
path
- 目录default boolean isDir(String dir)
dir
- 被判断的路径boolean mkdir(String dir)
dir
- 目录名void mkDirs(String dir)
dir
- 文件夹路径,绝对路径boolean delFile(String path)
path
- 目录路径boolean delDir(String dirPath)
dirPath
- 文件夹路径boolean uploadFile(String destPath, File file)
destPath
- 服务端路径,可以为null
或者相对路径或绝对路径file
- 需要上传的文件void recursiveDownloadFolder(String sourcePath, File destDir)
sourcePath
- ftp服务器目录destDir
- 本地目录InputStream getFileStream(String path)
path
- 文件路径InputStream
Copyright © 2025. All rights reserved.