public class SftpExecutor extends BaseSftpExecutor implements HostConnector
文件路必须是绝对路径 可以包含 ../ ./
bufferSize, charset
Constructor and Description |
---|
SftpExecutor(com.jcraft.jsch.ChannelSftp channel) |
SftpExecutor(com.jcraft.jsch.ChannelSftp channel,
String charset) |
Modifier and Type | Method and Description |
---|---|
void |
bufferSize(int bufferSize)
设置缓冲区大小
|
void |
changeGroup(String file,
int gid)
修改文件所有组
文件不存在则会报错
|
void |
changeMode(String file,
int permission)
修改文件权限
文件不存在则会报错
|
void |
changeOwner(String file,
int uid)
修改文件所有人
文件不存在则会报错
|
void |
charset(String charset)
设置文件名称编码格式
|
void |
close()
安全关闭
|
void |
connect()
建立连接
|
void |
connect(int timeout)
建立连接
使用此方法可能会导致连接不上 但是还不会抛出异常!
|
protected void |
doAppend(String path,
InputStream in,
StreamEntry entry)
执行拼接
|
protected void |
doMove(String source,
String target)
移动文件
|
protected long |
doTransfer(String path,
OutputStream out,
long skip,
int size,
boolean close)
执行传输
|
SftpDownloader |
download(String remote,
File local)
获取文件上传器
|
SftpDownloader |
download(String remote,
String local)
获取文件下载器
|
protected void |
doWrite(String path,
InputStream in,
StreamEntry entry)
执行写入
|
com.jcraft.jsch.ChannelSftp |
getChannel()
获取 channel
|
SftpFile |
getFile(String path)
获取文件属性
文件不存在返回 null
|
SftpFile |
getFile(String path,
boolean followSymbolic)
获取文件属性
文件不存在返回 null
|
String |
getHome()
获取根目录
|
String |
getLinkPath(String path)
获取连接文件的源文件
文件不存在 不会报错
不是连接文件 不会报错
|
String |
getPath(String path)
获取文件规范路径
文件不存在返回null
|
int |
getServerVersion()
获取服务端版本
|
long |
getSize(String path)
获取文件大小
如果不存在返回 -1
|
void |
hardLink(String source,
String target)
创建硬连接
原始文件不存在 则会报错
连接文件存在 则会报错
|
boolean |
isConnected()
检查 channel 是否已连接
|
boolean |
isExist(String path)
检查文件是否存在
文件不存在不会报错
|
void |
link(String source,
String target,
boolean hard)
创建连接文件
原始文件不存在 则会报错
连接文件存在 则会报错
|
List<SftpFile> |
list(String path)
获取目录文件属性
文件夹不存在则返回空
|
void |
makeDirectory(String path)
创建文件夹
文件夹存在 路径是文件并且已存在 父文件夹不存 则会报错
|
InputStream |
openInputStream(String path,
long skip)
打开存在文件的输入流
文件不存在会报错
|
OutputStream |
openOutputStream(String path,
boolean append)
打开存在文件的输出流
文件不存在会创建
|
OutputStream |
openOutputStream(String path,
int mode)
打开存在文件的输出流
|
int |
read(String path,
long skip,
byte[] bs,
int offset,
int len)
读取文件
文件不存在则报错
|
void |
removeDir(String path)
删除一个空的文件夹
文件夹不存在 不会报错
删除的是文件 不会报错 不会删除
不是空文件夹 会报错
|
void |
removeFile(String path)
删除一个普通文件
文件不存在 不会报错
删除的是文件夹 会报错
|
void |
sendSignal(String signal)
发送信号量
|
void |
setFileAttribute(SftpFile attribute)
设置文件属性
文件不存在则会报错
|
void |
setModifyTime(String path,
Date date)
设置文件修改时间
文件不存在则会报错
|
void |
symLink(String source,
String target)
创建软连接文件
原始文件不存在 则会报错
连接文件存在 则会报错
|
void |
touch(String path)
创建文件
文件是与存在的文件夹则会报错
|
void |
touch(String path,
boolean truncate)
创建文件
文件是与存在的文件夹则会报错
|
void |
touchTruncate(String path)
创建文件 如果文件存在则截断
文件是与存在的文件夹则会报错
|
void |
truncate(String path)
清空文件, 没有则创建
文件是与存在的文件夹则会报错
|
SftpUploader |
upload(String remote,
File local)
获取文件上传器
|
SftpUploader |
upload(String remote,
String local)
获取文件上传器
|
append, append, doMakeDir, downloadDir, downloadFile, downloadFile, getBufferSize, getCharset, isSameParentPath, listDirs, listFiles, listFilesFilter, makeDirectories, move, remove, transfer, transfer, uploadDir, uploadFile, uploadFile, write, write
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
disconnect, disconnectChannel, disconnectSession, getSession, isClosed, isEof
append, append, downloadDir, downloadDir, downloadDir, downloadFile, downloadFile, listDirs, listFiles, listFiles, listFilesFilter, listFilesFilter, openInputStream, openOutputStream, read, read, read, transfer, transfer, transfer, transfer, transfer, uploadDir, uploadDir, uploadDir, uploadFile, uploadFile, write, write
public SftpExecutor(com.jcraft.jsch.ChannelSftp channel)
public SftpExecutor(com.jcraft.jsch.ChannelSftp channel, String charset)
public void bufferSize(int bufferSize)
ISftpExecutor
bufferSize
in interface ISftpExecutor
bufferSize
- 缓冲区大小public void charset(String charset)
ISftpExecutor
charset
in interface ISftpExecutor
charset
- 编码格式public void sendSignal(String signal)
ISftpExecutor
sendSignal
in interface ISftpExecutor
signal
- 信号public String getHome()
ISftpExecutor
getHome
in interface ISftpExecutor
public boolean isExist(String path)
ISftpExecutor
文件不存在不会报错
isExist
in interface ISftpExecutor
path
- 文件绝对路径public String getPath(String path)
ISftpExecutor
文件不存在返回null
getPath
in interface ISftpExecutor
path
- 文件路径public String getLinkPath(String path)
ISftpExecutor
文件不存在 不会报错 不是连接文件 不会报错
getLinkPath
in interface ISftpExecutor
path
- 连接文件的绝对路径public SftpFile getFile(String path)
ISftpExecutor
文件不存在返回 null
getFile
in interface ISftpExecutor
path
- 文件绝对路径public SftpFile getFile(String path, boolean followSymbolic)
ISftpExecutor
文件不存在返回 null
getFile
in interface ISftpExecutor
path
- 文件绝对路径followSymbolic
- 如果是连接文件是否返回原文件属性public long getSize(String path)
ISftpExecutor
如果不存在返回 -1
getSize
in interface ISftpExecutor
path
- 文件绝对路径public void setFileAttribute(SftpFile attribute)
ISftpExecutor
文件不存在则会报错
setFileAttribute
in interface ISftpExecutor
attribute
- 文件属性public void setModifyTime(String path, Date date)
ISftpExecutor
文件不存在则会报错
setModifyTime
in interface ISftpExecutor
path
- 文件绝对路径date
- 修改时间public void changeMode(String file, int permission)
ISftpExecutor
文件不存在则会报错
changeMode
in interface ISftpExecutor
file
- 文件绝对路径permission
- 10进制表示的 8进制权限 如: 777public void changeOwner(String file, int uid)
ISftpExecutor
文件不存在则会报错
changeOwner
in interface ISftpExecutor
file
- 文件绝对路径uid
- 用户idpublic void changeGroup(String file, int gid)
ISftpExecutor
文件不存在则会报错
changeGroup
in interface ISftpExecutor
file
- 文件绝对路径gid
- 组idpublic void makeDirectory(String path)
ISftpExecutor
文件夹存在 路径是文件并且已存在 父文件夹不存 则会报错
makeDirectory
in interface ISftpExecutor
path
- 文件夹绝对路径public void removeDir(String path)
ISftpExecutor
文件夹不存在 不会报错 删除的是文件 不会报错 不会删除 不是空文件夹 会报错
removeDir
in interface ISftpExecutor
path
- 绝对路径public void removeFile(String path)
ISftpExecutor
文件不存在 不会报错 删除的是文件夹 会报错
removeFile
in interface ISftpExecutor
path
- 绝对路径public void touch(String path)
ISftpExecutor
文件是与存在的文件夹则会报错
touch
in interface ISftpExecutor
path
- 文件绝对路径public void touchTruncate(String path)
ISftpExecutor
文件是与存在的文件夹则会报错
touchTruncate
in interface ISftpExecutor
path
- 文件绝对路径public void touch(String path, boolean truncate)
ISftpExecutor
文件是与存在的文件夹则会报错
touch
in interface ISftpExecutor
path
- 文件绝对路径truncate
- 如果文件存在是否截断public void truncate(String path)
ISftpExecutor
文件是与存在的文件夹则会报错
truncate
in interface ISftpExecutor
path
- 文件绝对路径public void hardLink(String source, String target)
ISftpExecutor
原始文件不存在 则会报错 连接文件存在 则会报错
hardLink
in interface ISftpExecutor
source
- sourcetarget
- targetpublic void symLink(String source, String target)
ISftpExecutor
原始文件不存在 则会报错 连接文件存在 则会报错
symLink
in interface ISftpExecutor
source
- sourcetarget
- targetpublic void link(String source, String target, boolean hard)
ISftpExecutor
原始文件不存在 则会报错 连接文件存在 则会报错
link
in interface ISftpExecutor
source
- sourcetarget
- targethard
- 是否为硬链接protected void doMove(String source, String target)
BaseSftpExecutor
doMove
in class BaseSftpExecutor
source
- 原文件绝对路径target
- 目标文件 绝对路径 相对路径都可以public InputStream openInputStream(String path, long skip) throws IOException
ISftpExecutor
文件不存在会报错
openInputStream
in interface ISftpExecutor
path
- 文件路径skip
- 跳过的字节IOException
- IOExceptionpublic OutputStream openOutputStream(String path, boolean append) throws IOException
ISftpExecutor
文件不存在会创建
openOutputStream
in interface ISftpExecutor
path
- 文件路径append
- 是否为拼接IOException
- IOExceptionpublic OutputStream openOutputStream(String path, int mode) throws IOException
path
- 文件路径mode
- 0 完全覆盖模式
1 恢复模式
2 追加模式IOException
- IOExceptionpublic int read(String path, long skip, byte[] bs, int offset, int len) throws IOException
ISftpExecutor
文件不存在则报错
read
in interface ISftpExecutor
path
- 文件绝对路径skip
- 跳过字节数bs
- 字节数组offset
- offsetlen
- lenIOException
- IOExceptionprotected long doTransfer(String path, OutputStream out, long skip, int size, boolean close) throws IOException
BaseSftpExecutor
doTransfer
in class BaseSftpExecutor
path
- pathout
- outskip
- skipsize
- sizeclose
- closeIOException
- IOExceptionprotected void doWrite(String path, InputStream in, StreamEntry entry) throws IOException
BaseSftpExecutor
doWrite
in class BaseSftpExecutor
path
- pathin
- inentry
- entryIOException
- IOExceptionprotected void doAppend(String path, InputStream in, StreamEntry entry) throws IOException
BaseSftpExecutor
doAppend
in class BaseSftpExecutor
path
- pathin
- inentry
- entryIOException
- IOExceptionpublic SftpUploader upload(String remote, File local)
ISftpExecutor
upload
in interface ISftpExecutor
remote
- 远程文件绝对路径local
- 本地文件public SftpUploader upload(String remote, String local)
ISftpExecutor
upload
in interface ISftpExecutor
remote
- 远程文件绝对路径local
- 本地文件public SftpDownloader download(String remote, File local)
ISftpExecutor
download
in interface ISftpExecutor
remote
- 远程文件绝对路径local
- 本地文件public SftpDownloader download(String remote, String local)
ISftpExecutor
download
in interface ISftpExecutor
remote
- 远程文件绝对路径local
- 本地文件public List<SftpFile> list(String path)
ISftpExecutor
文件夹不存在则返回空
list
in interface ISftpExecutor
path
- 文件绝对路径public void connect()
HostConnector
connect
in interface HostConnector
public void connect(int timeout)
HostConnector
Channel.sendChannelOpen()
的 retry 设置为 1connect
in interface HostConnector
timeout
- 超时时间 mspublic boolean isConnected()
HostConnector
isConnected
in interface HostConnector
isConnected
in interface ISftpExecutor
public int getServerVersion()
ISftpExecutor
getServerVersion
in interface ISftpExecutor
public void close()
SafeCloseable
close
in interface SafeCloseable
close
in interface Closeable
close
in interface AutoCloseable
public com.jcraft.jsch.ChannelSftp getChannel()
HostConnector
getChannel
in interface HostConnector
Copyright © 2024. All rights reserved.