java删除sftp文件夹_java 通过sftp服务器上传下载删除文件

最近做了一个sftp服务器文件下载的功能,mark一下:

首先是一个SftpClientUtil 类,封装了对sftp服务器文件上传、下载、删除的方法importjava.io.File;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.InputStream;importjava.util.ArrayList;importjava.util.Iterator;importjava.util.List;importjava.util.Properties;importjava.util.Vector;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importcom.jcraft.jsch.Channel;importcom.jcraft.jsch.ChannelSftp;importcom.jcraft.jsch.ChannelSftp.LsEntry;importcom.jcraft.jsch.JSch;importcom.jcraft.jsch.Session;public classSftpClientUtil {/*** 初始化日志引擎*/

private final Logger logger = LoggerFactory.getLogger(SftpClientUtil.class);/**Sftp*/ChannelSftp sftp= null;/**主机*/

private String host = "";/**端口*/

private int port = 0;/**用户名*/

private String username = "";/**密码*/

private String password = "";/*** 构造函数

*

*@paramhost

* 主机

*@paramport

* 端口

*@paramusername

* 用户名

*@parampassword

* 密码

**/

public SftpClientUtil(String host, intport, String username,

String password){this.host =host;this.port =port;this.username =username;this.password =password;

}/*** 连接sftp服务器

*

*@throwsException*/

public void connect() throwsException {

JSch jsch= newJSch();

Session sshSession= jsch.getSession(this.username, this.host, this.port);

logger.debug(SftpClientUtil.class + "Session created.");

sshSession.setPassword(password);

Properties sshConfig= newProperties();

sshConfig.put("StrictHostKeyChecking", "no");

sshSession.setConfig(sshConfig);

sshSession.connect(20000);

logger.debug(SftpClientUtil.class + " Session connected.");

logger.debug(SftpClientUtil.class + " Opening Channel.");

Channel channel= sshSession.openChannel("sftp");

channel.connect();this.sftp =(ChannelSftp) ch

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值