public class SshjSftp extends AbstractFtp
基于sshj 框架适配。
参考:https://github.com/hierynomus/sshj
DEFAULT_CHARSET, ftpConfig| 限定符 | 构造器和说明 |
|---|---|
protected |
SshjSftp(FtpConfig config)
构造
|
|
SshjSftp(String sshHost)
构造,使用默认端口
|
|
SshjSftp(String sshHost,
int sshPort,
String sshUser,
String sshPass)
构造
|
|
SshjSftp(String sshHost,
int sshPort,
String sshUser,
String sshPass,
Charset charset)
构造
|
|
SshjSftp(String sshHost,
String sshUser,
String sshPass)
构造
|
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
cd(String directory)
打开指定目录,具体逻辑取决于实现,例如在FTP中,进入失败返回
false, SFTP中则抛出异常 |
void |
close() |
String |
command(String exec)
执行Linux 命令
|
boolean |
containsFile(String fileDir)
是否包含该文件
|
boolean |
delDir(String dirPath)
删除文件夹及其文件夹下的所有文件
|
boolean |
delFile(String path)
删除指定目录下的指定文件
|
void |
download(String path,
File outFile)
下载文件
|
void |
init()
SSH 初始化并创建一个sftp客户端.
|
List<String> |
ls(String path)
遍历某个目录下所有文件和目录,不会递归遍历
|
boolean |
mkdir(String dir)
在当前远程目录(工作目录)下创建新的目录
|
String |
pwd()
远程当前目录(工作目录)
|
AbstractFtp |
reconnectIfTimeout()
如果连接超时的话,重新进行连接
|
void |
recursiveDownloadFolder(String sourcePath,
File destDir)
递归下载FTP服务器上文件到本地(文件目录和服务器同步), 服务器上有新文件会覆盖本地文件
|
boolean |
uploadFile(String destPath,
File file)
将本地文件上传到目标服务器,目标文件名为destPath,若destPath为目录,则目标文件名将与file文件名相同。
|
public SshjSftp(String sshHost)
sshHost - 主机public SshjSftp(String sshHost, String sshUser, String sshPass)
sshHost - 主机sshUser - 用户名sshPass - 密码public SshjSftp(String sshHost, int sshPort, String sshUser, String sshPass)
sshHost - 主机sshPort - 端口sshUser - 用户名sshPass - 密码public SshjSftp(String sshHost, int sshPort, String sshUser, String sshPass, Charset charset)
sshHost - 主机sshPort - 端口sshUser - 用户名sshPass - 密码charset - 编码protected SshjSftp(FtpConfig config)
config - FTP配置public void init()
public AbstractFtp reconnectIfTimeout()
AbstractFtpreconnectIfTimeout 在类中 AbstractFtppublic boolean cd(String directory)
AbstractFtpfalse, SFTP中则抛出异常cd 在类中 AbstractFtpdirectory - directorypublic String pwd()
AbstractFtppwd 在类中 AbstractFtppublic boolean mkdir(String dir)
AbstractFtpmkdir 在类中 AbstractFtpdir - 目录名public List<String> ls(String path)
AbstractFtpls 在类中 AbstractFtppath - 需要遍历的目录public boolean delFile(String path)
AbstractFtpdelFile 在类中 AbstractFtppath - 目录路径public boolean delDir(String dirPath)
AbstractFtpdelDir 在类中 AbstractFtpdirPath - 文件夹路径public boolean uploadFile(String destPath, File file)
AbstractFtpuploadFile 在类中 AbstractFtpdestPath - 服务端路径,可以为null 或者相对路径或绝对路径file - 需要上传的文件public void download(String path, File outFile)
AbstractFtpdownload 在类中 AbstractFtppath - 文件路径outFile - 输出文件或目录public void recursiveDownloadFolder(String sourcePath, File destDir)
AbstractFtprecursiveDownloadFolder 在类中 AbstractFtpsourcePath - ftp服务器目录destDir - 本地目录public void close()
public boolean containsFile(String fileDir)
fileDir - 文件绝对路径Copyright © 2023. All rights reserved.