public class FTPUtil extends Object
| 构造器和说明 |
|---|
FTPUtil() |
FTPUtil(String host,
String account,
String password) |
FTPUtil(String host,
String account,
String password,
int port) |
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
cd(String dir) |
boolean |
changeToParentDirectory() |
void |
connect() |
void |
deleteFile(String ftpFileName)
Delete the file from the FTP server.
|
void |
disconnect() |
boolean |
downloadDir(String remoteDir,
File localDir)
下载整个目录
|
boolean |
downloadFile(String remote,
File local)
下载单个文件
|
List<String> |
files(String dir) |
int |
fileSize(String dir) |
static List<String> |
formatPath(String srcPath)
格式化路径.
|
String |
getDir() |
org.apache.commons.net.ftp.FTPClient |
getFTPClient() |
static FTPUtil |
getInstance(String host,
String account,
String password) |
static FTPUtil |
getInstance(String host,
String account,
String password,
int port) |
String |
getParentDirectory()
Get parent directory name on ftp server
|
boolean |
isConnected()
Test connection to ftp server
|
boolean |
makeDir(String path)
创建目录
|
String |
printWorkingDirectory() |
boolean |
rename(String from,
String to)
修改名称
|
void |
retrieveFile(String ftpFileName,
OutputStream out)
Get file from ftp server into given output stream
|
void |
sendSiteCommand(String args) |
void |
setControlEncoding(String charset) |
void |
setFileType(int fileType) |
void |
setTimeOut(int defaultTimeoutSecond,
int connectTimeoutSecond,
int dataTimeoutSecond) |
void |
storeFile(String ftpFileName,
InputStream in)
Put file on ftp server from given input stream
|
boolean |
upload(String remote,
File local) |
void |
uploadDir(String remotePath,
File local)
上传目录(会覆盖)
|
boolean |
uploadFile(File local,
String remote) |
boolean |
uploadFile(String remote,
File local) |
public static FTPUtil getInstance(String host, String account, String password, int port)
public void setTimeOut(int defaultTimeoutSecond,
int connectTimeoutSecond,
int dataTimeoutSecond)
public int fileSize(String dir)
public boolean downloadFile(String remote, File local)
remote - remotelocal - localpublic org.apache.commons.net.ftp.FTPClient getFTPClient()
public void setControlEncoding(String charset)
public void setFileType(int fileType)
throws IOException
IOExceptionpublic void connect()
public boolean isConnected()
public void disconnect()
public void retrieveFile(String ftpFileName, OutputStream out) throws IOException
ftpFileName - file name on ftp serverout - OutputStreamIOException - IOExceptionpublic void storeFile(String ftpFileName, InputStream in) throws IOException
ftpFileName - file name on ftp serverin - InputStreamIOException - IOExceptionpublic boolean rename(String from, String to) throws IOException
from - fromto - toIOException - IOExceptionpublic void deleteFile(String ftpFileName) throws IOException
ftpFileName - server file name (with absolute path)IOException - on I/O errorspublic void uploadDir(String remotePath, File local)
remotePath - 远程目录 /home/test/alocal - 本地目录 D:/test/apublic boolean downloadDir(String remoteDir, File localDir)
remoteDir - remoteDirlocalDir - localDirpublic boolean cd(String dir)
public List<String> files(String dir) throws IOException
IOExceptionpublic void sendSiteCommand(String args) throws IOException
IOExceptionpublic String printWorkingDirectory()
public boolean changeToParentDirectory()
public String getParentDirectory()
public boolean makeDir(String path) throws IOException
path - pathIOException - IOExceptionpublic static List<String> formatPath(String srcPath)
srcPath - 原路径. /xxx/xxx/xxx.yyy 或 X:/xxx/xxx/xxx.yypublic String getDir()
Copyright © 2024. All rights reserved.