public class Ftp extends AbstractFtp
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_PORT
默认端口
|
DEFAULT_CHARSET, ftpConfig| Constructor and Description |
|---|
Ftp(FtpConfig config,
FtpMode mode)
构造
|
Ftp(String host)
构造,匿名登录
|
Ftp(String host,
int port)
构造,匿名登录
|
Ftp(String host,
int port,
String user,
String password)
构造
|
Ftp(String host,
int port,
String user,
String password,
Charset charset)
构造
|
Ftp(String host,
int port,
String user,
String password,
Charset charset,
FtpMode mode)
构造
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
cd(String directory)
改变目录
|
void |
close() |
boolean |
delDir(String dirPath)
删除文件夹及其文件夹下的所有文件
|
boolean |
delFile(String path)
删除指定目录下的指定文件
|
void |
download(String path,
File outFile)
下载文件
|
void |
download(String sourcePath,
String desPath)
递归获取远程文件
|
void |
download(String path,
String fileName,
File outFile)
下载文件
|
void |
download(String path,
String fileName,
OutputStream out)
下载文件到输出流
|
boolean |
existFile(String path)
判断ftp服务器文件是否存在
|
org.apache.commons.net.ftp.FTPClient |
getClient()
获取FTPClient客户端对象
|
Ftp |
init()
初始化连接
|
Ftp |
init(FtpConfig config,
FtpMode mode)
初始化连接
|
Ftp |
init(String host,
int port,
String user,
String password)
初始化连接
|
Ftp |
init(String host,
int port,
String user,
String password,
FtpMode mode)
初始化连接
|
List<String> |
ls(String path)
遍历某个目录下所有文件和目录,不会递归遍历
|
org.apache.commons.net.ftp.FTPFile[] |
lsFiles(String path)
遍历某个目录下所有文件和目录,不会递归遍历
|
boolean |
mkdir(String dir)
在当前远程目录(工作目录)下创建新的目录
|
String |
pwd()
远程当前目录
|
Ftp |
reconnectIfTimeout()
如果连接超时的话,重新进行连接 经测试,当连接超时时,client.isConnected()仍然返回ture,无法判断是否连接超时 因此,通过发送pwd命令的方式,检查连接是否超时
|
Ftp |
setBackToPwd(boolean backToPwd)
设置执行完操作是否返回当前目录
|
Ftp |
setMode(FtpMode mode)
设置FTP连接模式,可选主动和被动模式
|
int |
stat(String path)
获取服务端目录状态。
|
boolean |
upload(String destPath,
File file)
上传文件到指定目录,可选:
|
boolean |
upload(String path,
String fileName,
File file)
上传文件到指定目录,可选:
|
boolean |
upload(String path,
String fileName,
InputStream fileStream)
上传文件到指定目录,可选:
|
exist, mkDirs, toParentpublic static final int DEFAULT_PORT
public Ftp(String host)
host - 域名或IPpublic Ftp(String host, int port)
host - 域名或IPport - 端口public Ftp(String host, int port, String user, String password)
host - 域名或IPport - 端口user - 用户名password - 密码public Ftp(String host, int port, String user, String password, Charset charset)
host - 域名或IPport - 端口user - 用户名password - 密码charset - 编码public Ftp(String host, int port, String user, String password, Charset charset, FtpMode mode)
host - 域名或IPport - 端口user - 用户名password - 密码charset - 编码mode - 模式public Ftp init()
public Ftp init(String host, int port, String user, String password)
host - 域名或IPport - 端口user - 用户名password - 密码public Ftp init(String host, int port, String user, String password, FtpMode mode)
host - 域名或IPport - 端口user - 用户名password - 密码mode - 模式public Ftp init(FtpConfig config, FtpMode mode)
config - FTP配置mode - 模式public Ftp setBackToPwd(boolean backToPwd)
backToPwd - 执行完操作是否返回当前目录public Ftp reconnectIfTimeout()
reconnectIfTimeout in class AbstractFtppublic boolean cd(String directory)
cd in class AbstractFtpdirectory - 目录public String pwd()
pwd in class AbstractFtppublic List<String> ls(String path)
AbstractFtpls in class AbstractFtppath - 需要遍历的目录public org.apache.commons.net.ftp.FTPFile[] lsFiles(String path)
path - 目录public boolean mkdir(String dir)
AbstractFtpmkdir in class AbstractFtpdir - 目录名public boolean existFile(String path)
path - 文件路径public int stat(String path)
path - 路径public boolean delFile(String path)
AbstractFtpdelFile in class AbstractFtppath - 目录路径public boolean delDir(String dirPath)
AbstractFtpdelDir in class AbstractFtpdirPath - 文件夹路径public boolean upload(String destPath, File file)
1. path为null或""上传到当前路径 2. path为相对路径则相对于当前路径的子路径 3. path为绝对路径则上传到此路径
upload in class AbstractFtpdestPath - 服务端路径,可以为null 或者相对路径或绝对路径file - 文件public boolean upload(String path, String fileName, File file)
1. path为null或""上传到当前路径 2. path为相对路径则相对于当前路径的子路径 3. path为绝对路径则上传到此路径
file - 文件path - 服务端路径,可以为null 或者相对路径或绝对路径fileName - 自定义在服务端保存的文件名public boolean upload(String path, String fileName, InputStream fileStream)
1. path为null或""上传到当前路径 2. path为相对路径则相对于当前路径的子路径 3. path为绝对路径则上传到此路径
path - 服务端路径,可以为null 或者相对路径或绝对路径fileName - 文件名fileStream - 文件流public void download(String path, File outFile)
download in class AbstractFtppath - 文件路径outFile - 输出文件或目录public void download(String path, String fileName, File outFile)
path - 文件路径fileName - 文件名outFile - 输出文件或目录public void download(String path, String fileName, OutputStream out)
path - 文件路径fileName - 文件名out - 输出位置public void download(String sourcePath, String desPath)
download in class AbstractFtpsourcePath - 服务器目录desPath - 本地目录public org.apache.commons.net.ftp.FTPClient getClient()
FTPClientpublic void close()
throws IOException
IOExceptionCopyright © 2021. All rights reserved.