程序包 org.anyline.net
类 FTPUtil
- java.lang.Object
-
- org.anyline.net.FTPUtil
-
public class FTPUtil extends Object
-
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 booleancd(String dir)booleanchangeToParentDirectory()voidconnect()voiddeleteFile(String ftpFileName)Delete the file from the FTP server.voiddisconnect()booleandownloadDir(String remoteDir, File localDir)下载整个目录booleandownloadFile(String remote, File local)下载单个文件List<String>files(String dir)intfileSize(String dir)static List<String>formatPath(String origin)格式化路径.StringgetDir()org.apache.commons.net.ftp.FTPClientgetFTPClient()static FTPUtilgetInstance(String host, String account, String password)static FTPUtilgetInstance(String host, String account, String password, int port)StringgetParentDirectory()Get parent directory name on ftp serverbooleanisConnected()Test connection to ftp serverbooleanmakeDir(String path)创建目录StringprintWorkingDirectory()booleanrename(String from, String to)修改名称voidretrieveFile(String ftpFileName, OutputStream out)Get file from ftp server into given output streamvoidsendSiteCommand(String args)voidsetControlEncoding(String charset)voidsetFileType(int fileType)voidsetTimeOut(int defaultTimeoutSecond, int connectTimeoutSecond, int dataTimeoutSecond)voidstoreFile(String ftpFileName, InputStream in)Put file on ftp server from given input streambooleanupload(String remote, File local)voiduploadDir(String remotePath, File local)上传目录(会覆盖)booleanuploadFile(File local, String remote)booleanuploadFile(String remote, File local)
-
-
-
方法详细资料
-
getInstance
public static FTPUtil getInstance(String host, String account, String password, int port)
-
setTimeOut
public void setTimeOut(int defaultTimeoutSecond, int connectTimeoutSecond, int dataTimeoutSecond)
-
fileSize
public int fileSize(String dir)
-
downloadFile
public boolean downloadFile(String remote, File local)
下载单个文件- 参数:
remote- remotelocal- local- 返回:
- boolean
-
getFTPClient
public org.apache.commons.net.ftp.FTPClient getFTPClient()
-
setControlEncoding
public void setControlEncoding(String charset)
-
setFileType
public void setFileType(int fileType) throws IOException- 抛出:
IOException
-
connect
public void connect()
-
isConnected
public boolean isConnected()
Test connection to ftp server- 返回:
- true, if connected
-
disconnect
public void disconnect()
-
retrieveFile
public void retrieveFile(String ftpFileName, OutputStream out) throws IOException
Get file from ftp server into given output stream- 参数:
ftpFileName- file name on ftp serverout- OutputStream- 抛出:
IOException- IOException
-
storeFile
public void storeFile(String ftpFileName, InputStream in) throws IOException
Put file on ftp server from given input stream- 参数:
ftpFileName- file name on ftp serverin- InputStream- 抛出:
IOException- IOException
-
rename
public boolean rename(String from, String to) throws IOException
修改名称- 参数:
from- fromto- to- 返回:
- boolean
- 抛出:
IOException- IOException
-
deleteFile
public void deleteFile(String ftpFileName) throws IOException
Delete the file from the FTP server.- 参数:
ftpFileName- server file name (with absolute path)- 抛出:
IOException- on I/O errors
-
uploadDir
public void uploadDir(String remotePath, File local)
上传目录(会覆盖)- 参数:
remotePath- 远程目录 /home/test/alocal- 本地目录 D:/test/a
-
downloadDir
public boolean downloadDir(String remoteDir, File localDir)
下载整个目录- 参数:
remoteDir- remoteDirlocalDir- localDir- 返回:
- boolean
-
cd
public boolean cd(String dir)
-
files
public List<String> files(String dir) throws IOException
- 抛出:
IOException
-
sendSiteCommand
public void sendSiteCommand(String args) throws IOException
- 抛出:
IOException
-
printWorkingDirectory
public String printWorkingDirectory()
-
changeToParentDirectory
public boolean changeToParentDirectory()
-
getParentDirectory
public String getParentDirectory()
Get parent directory name on ftp server- 返回:
- parent directory
-
makeDir
public boolean makeDir(String path) throws IOException
创建目录- 参数:
path- path- 返回:
- boolean
- 抛出:
IOException- IOException
-
formatPath
public static List<String> formatPath(String origin)
格式化路径.- 参数:
origin- 原路径. /xxx/xxx/xxx.yyy 或 X:/xxx/xxx/xxx.yy- 返回:
- list, 第一个是路径(/xxx/xxx/), 第二个是文件名(xxx.yy)
-
getDir
public String getDir()
-
-