FtpClient工具类
Type | Name and description |
---|---|
static org.apache.commons.net.ftp.FTPClient |
connect(String host, Integer port = 21, String username = "anonymous", String password = "anonymous@bropen.com.cn") 连接并登录FTP服务器。 |
static void |
disconnect(org.apache.commons.net.ftp.FTPClient ftp) 断开FTP连接 |
static boolean |
get(org.apache.commons.net.ftp.FTPClient ftp, String remotePath, String localPath) 下载文件。 |
static boolean |
put(org.apache.commons.net.ftp.FTPClient ftp, String remotePath, String localFile) 上传文件,如果文件已存在,则自动覆盖。 |
Methods inherited from class | Name |
---|---|
class Object |
Object#wait(long), Object#wait(long, int), Object#wait(), Object#equals(Object), Object#toString(), Object#hashCode(), Object#getClass(), Object#notify(), Object#notifyAll() |
连接并登录FTP服务器。
如果发现中文乱码(或无法上传中文名的文件),可以尝试手动设置字符集后再上传、下载,如:ftp.setControlEncoding("GBK")。
执行完FTP操作后,务必在 finally 中调用 disconnect 以关闭连接。
断开FTP连接
下载文件。如果本地文件已存在,则自动覆盖。
remotePath
- 远程文件名全路径,如 “/foo/bar.doc”localPath
- 本地文件名全路径,或文件夹(以"/"或"\\"结尾)上传文件,如果文件已存在,则自动覆盖。
remotePath
- 远程文件夹(以“/”结尾)或文件名的全路径localFile
- 本地文件名全路径