程序包 org.anyline.net
类 SFTPUtil
- java.lang.Object
-
- org.anyline.net.SFTPUtil
-
public class SFTPUtil extends Object
-
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 voiddeleteDir(String path)删除文件夹-sftp协议.如果文件夹有内容, 则会抛出异常.voiddeleteFile(String path)删除文件-sftp协议.booleandirExist(String dir)判断文件夹是否存在.booleandisconnect()断开连接voiddownload(String remote, String local)下载文件-sftp协议.booleanfileExists(String path)booleanfileExists(String dir, String file)List<String>files(String dir)intfileSize(String remoteDir)static SFTPUtilgetInstance(String host, String account, String password)static SFTPUtilgetInstance(String host, String account, String password, int port)booleanmkdir(String dir)根据路径创建文件夹.booleanmkdirs(String dir)递归创建文件夹.voiduploadFile(File localFile, String remoteDir, String remoteFile)booleanuploadFile(String localFile)上传文件-sftp协议.voiduploadFile(String localFile, String remoteDir, String remoteFile)上传文件-sftp协议.
-
-
-
方法详细资料
-
getInstance
public static SFTPUtil getInstance(String host, String account, String password, int port)
-
download
public void download(String remote, String local) throws Exception
下载文件-sftp协议.- 参数:
remote- 下载的文件local- 存在本地的路径- 抛出:
Exception- 异常 异常
-
disconnect
public boolean disconnect()
断开连接- 返回:
- boolean
-
fileSize
public int fileSize(String remoteDir)
-
deleteFile
public void deleteFile(String path) throws com.jcraft.jsch.SftpException
删除文件-sftp协议.- 参数:
path- 要删除的文件- 抛出:
com.jcraft.jsch.SftpException- 异常
-
deleteDir
public void deleteDir(String path) throws com.jcraft.jsch.SftpException
删除文件夹-sftp协议.如果文件夹有内容, 则会抛出异常.- 参数:
path- 文件夹路径- 抛出:
com.jcraft.jsch.SftpException- SftpException
-
uploadFile
public void uploadFile(String localFile, String remoteDir, String remoteFile) throws com.jcraft.jsch.SftpException
上传文件-sftp协议.- 参数:
localFile- 源文件remoteDir- 远程保存路径remoteFile- 远程保存文件名- 抛出:
com.jcraft.jsch.SftpException- 异常
-
uploadFile
public void uploadFile(File localFile, String remoteDir, String remoteFile) throws com.jcraft.jsch.SftpException
- 抛出:
com.jcraft.jsch.SftpException
-
uploadFile
public boolean uploadFile(String localFile) throws com.jcraft.jsch.SftpException
上传文件-sftp协议.- 参数:
localFile- 源文件路径, /xxx/xx.yy 或 x:/xxx/xxx.yy- 返回:
- 上传成功与否
- 抛出:
com.jcraft.jsch.SftpException- 异常
-
mkdir
public boolean mkdir(String dir) throws com.jcraft.jsch.SftpException
根据路径创建文件夹.- 参数:
dir- 路径 必须是 /xxx/xxx/ 不能就单独一个/- 返回:
- boolean
- 抛出:
com.jcraft.jsch.SftpException- 异常
-
mkdirs
public boolean mkdirs(String dir) throws com.jcraft.jsch.SftpException
递归创建文件夹.- 参数:
dir- 路径- 返回:
- 是否执行成功
- 抛出:
com.jcraft.jsch.SftpException- 异常
-
dirExist
public boolean dirExist(String dir)
判断文件夹是否存在.- 参数:
dir- 文件夹路径, /xxx/xxx/- 返回:
- 是否存在
-
fileExists
public boolean fileExists(String path)
-
-