public class FtpInstance extends BaseFtpInstance
bufferSize, client, config, pool, SEPARATOR
Constructor and Description |
---|
FtpInstance(org.apache.commons.net.ftp.FTPClient client,
FtpConfig config) |
FtpInstance(FtpClientPool pool) |
Modifier and Type | Method and Description |
---|---|
void |
change()
切换至根目录
|
void |
change(String dir)
切换目录
目标目录不存在不会报错
|
protected void |
doAppend(String path,
InputStream in,
StreamEntry entry)
执行拼接
|
protected long |
doTransfer(String path,
OutputStream out,
long skip,
int size,
boolean close)
执行传输
|
FtpDownloader |
download(String remote,
File local)
获取大文件下载器
|
FtpDownloader |
download(String remote,
String local)
获取大文件下载器
|
void |
downloadDir(String remoteDir,
String localDir,
boolean child)
下载文件夹
|
void |
downloadFile(String remoteFile,
OutputStream out,
boolean close)
下载文件
|
protected void |
doWrite(String path,
InputStream in,
StreamEntry entry)
执行写入
|
FtpFile |
getFile(String file)
获取文件属性
文件不存在不会报错
|
long |
getModifyTime(String file)
获取文件最后修改时间
文件不存在返回 -1
|
long |
getSize(String file)
获取文件大小
文件不存在返回 -1
|
String |
getWorkDirectory()
获取工作目录
|
boolean |
isExist(String file)
文件是否存在
文件不存在不会报错
|
List<FtpFile> |
listFilesFilter(String path,
FtpFileFilter filter,
boolean child,
boolean dir)
列出目录下的文件
|
void |
makeDirectories(String dir)
创建文件夹
文件夹已存在或存在的为文件不会报错
|
void |
move(String source,
String target)
文件移动/重命名
文件不存在不会报错
目标文件存在不会报错
|
InputStream |
openInputStream(String file,
long skip)
获取文件输入流
文件不存在则报错
使用完毕需要调用 client.completePendingCommand();
这个操作在关闭 io 之后 | finally 中
|
OutputStream |
openOutputStream(String file,
boolean append)
获取文件输出流
文件存在则自动创建
使用完毕需要调用 client.completePendingCommand();
这个操作在关闭 io 之后 | finally 中
|
int |
read(String file,
long skip,
byte[] bs,
int off,
int len)
读取文件到数组
文件不存在则报错
|
void |
remove(String file)
删除文件或递归删除文件及目录
文件不存在不会报错
|
void |
removeDir(String dir)
递归删除目录及文件
文件不存在不会报错
删除的是文件不会报错
|
void |
removeFile(String file)
删除文件
文件不存在不会报错
删除的是文件夹不会报错
|
void |
setModifyTime(String file,
Date time)
设置文件最后修改时间
文件不存在则会报错
|
void |
touch(String file)
创建文件
文件已存在不会报错
|
void |
truncate(String file)
清空文件
如果文件不存在不会报错
如果是文件夹则会报错
|
FtpUploader |
upload(String remote,
File local)
获取大文件上传器
|
FtpUploader |
upload(String remote,
String local)
获取大文件下载器
|
void |
uploadDir(String remoteDir,
String localDir,
boolean child)
上传文件夹
/root/target > /home/ljh/target
如果远程文件夹不设置 /target 则会将 /home/ljh/target 的文件传输到 /root
远程文件夹不存在不会报错
远程文件夹是个文件则会报错
|
void |
uploadFile(String remoteFile,
InputStream in,
boolean close)
上传文件
远程文件存在则会覆盖
远程文件是个文件夹则会报错
|
append, append, close, destroy, downloadFile, getClient, getConfig, getPool, getStatus, getStatus, getSystemType, listDirs, listFiles, localCharset, pending, reply, replyCode, replyMsg, reset, restartOffset, sendNoop, serverCharset, transfer, transfer, uploadFile, write, write
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
append, append, downloadDir, downloadDir, downloadDir, downloadFile, downloadFile, listDirs, listFiles, listFiles, listFilesFilter, listFilesFilter, openInputStream, openOutputStream, read, read, read, transfer, transfer, transfer, transfer, transfer, transfer, uploadDir, uploadDir, uploadDir, uploadFile, uploadFile, write, write
public FtpInstance(FtpClientPool pool)
public FtpInstance(org.apache.commons.net.ftp.FTPClient client, FtpConfig config)
public void change()
IFtpInstance
public void change(String dir)
IFtpInstance
目标目录不存在不会报错
dir
- dirpublic String getWorkDirectory()
IFtpInstance
public boolean isExist(String file)
IFtpInstance
文件不存在不会报错
file
- 文件public FtpFile getFile(String file)
IFtpInstance
文件不存在不会报错
file
- 文件public long getSize(String file)
IFtpInstance
文件不存在返回 -1
file
- filepublic long getModifyTime(String file)
IFtpInstance
文件不存在返回 -1
file
- filepublic void setModifyTime(String file, Date time)
IFtpInstance
文件不存在则会报错
file
- filetime
- timepublic void truncate(String file) throws IOException
IFtpInstance
如果文件不存在不会报错 如果是文件夹则会报错
file
- fileIOException
- IOExceptionpublic void remove(String file)
IFtpInstance
文件不存在不会报错
file
- filepublic void removeFile(String file)
IFtpInstance
文件不存在不会报错 删除的是文件夹不会报错
file
- 文件public void removeDir(String dir)
IFtpInstance
文件不存在不会报错 删除的是文件不会报错
dir
- 目录public void makeDirectories(String dir)
IFtpInstance
文件夹已存在或存在的为文件不会报错
dir
- 文件夹public void touch(String file)
IFtpInstance
文件已存在不会报错
file
- 文件public void move(String source, String target)
IFtpInstance
文件不存在不会报错 目标文件存在不会报错
source
- 原文件路径target
- 移动后的路径 可以为相对路径 如果不加目录为重命名public InputStream openInputStream(String file, long skip) throws IOException
IFtpInstance
文件不存在则报错 使用完毕需要调用 client.completePendingCommand(); 这个操作在关闭 io 之后 | finally 中
file
- 文件skip
- 跳过字节数IOException
- IOExceptionpublic OutputStream openOutputStream(String file, boolean append) throws IOException
IFtpInstance
文件存在则自动创建 使用完毕需要调用 client.completePendingCommand(); 这个操作在关闭 io 之后 | finally 中
file
- 文件append
- 是否为拼接IOException
- IOExceptionpublic int read(String file, long skip, byte[] bs, int off, int len) throws IOException
IFtpInstance
文件不存在则报错
file
- 文件skip
- 跳过字节数bs
- 数组off
- 偏移量len
- 长度IOException
- IOExceptionprotected long doTransfer(String path, OutputStream out, long skip, int size, boolean close) throws IOException
BaseFtpInstance
doTransfer
in class BaseFtpInstance
path
- pathout
- outskip
- skipsize
- sizeclose
- closeIOException
- IOExceptionprotected void doWrite(String path, InputStream in, StreamEntry entry) throws IOException
BaseFtpInstance
doWrite
in class BaseFtpInstance
path
- pathin
- inentry
- entryIOException
- IOExceptionprotected void doAppend(String path, InputStream in, StreamEntry entry) throws IOException
BaseFtpInstance
doAppend
in class BaseFtpInstance
path
- pathin
- inentry
- entryIOException
- IOExceptionpublic void uploadFile(String remoteFile, InputStream in, boolean close) throws IOException
IFtpInstance
远程文件存在则会覆盖
远程文件是个文件夹则会报错
remoteFile
- 远程文件in
- inputclose
- closeIOException
- IOExceptionpublic void uploadDir(String remoteDir, String localDir, boolean child) throws IOException
IFtpInstance
/root/target > /home/ljh/target 如果远程文件夹不设置 /target 则会将 /home/ljh/target 的文件传输到 /root
远程文件夹不存在不会报错 远程文件夹是个文件则会报错
remoteDir
- 远程文件夹localDir
- 本地文件夹 上传时不包含此文件夹child
- 是否遍历上传IOException
- IOExceptionpublic void downloadFile(String remoteFile, OutputStream out, boolean close) throws IOException
IFtpInstance
remoteFile
- 远程文件路径out
- outputclose
- 是否自动关闭IOException
- pendingpublic void downloadDir(String remoteDir, String localDir, boolean child) throws IOException
IFtpInstance
remoteDir
- 远程文件夹localDir
- 本地文件夹child
- 是否递归子文件夹下载IOException
- pendingpublic FtpUploader upload(String remote, String local)
IFtpInstance
remote
- 远程文件local
- 本地文件public FtpUploader upload(String remote, File local)
IFtpInstance
remote
- 远程文件local
- 本地文件public FtpDownloader download(String remote, String local)
IFtpInstance
remote
- 远程文件local
- 本地文件public FtpDownloader download(String remote, File local)
IFtpInstance
remote
- 远程文件local
- 本地文件public List<FtpFile> listFilesFilter(String path, FtpFileFilter filter, boolean child, boolean dir)
IFtpInstance
path
- 目录filter
- 过滤器child
- 是否递归子文件夹dir
- 是否添加文件夹Copyright © 2024. All rights reserved.