sftp服务器删除非空文件命令,SFTP非空文件夹递归删除(SFTP non-empty folder delete recursively)...

I tried JSCH for deleting non empty folder via SFTP, but it did not work.

This one works, but it is not free :( I am already past 30 days trial period. My company refuse to pay them for just deleting the folder via SFTP.

package com.test.cvsutil;

import java.util.List;

import org.apache.log4j.Logger;

import com.jscape.inet.sftp.Sftp;

import com.jscape.inet.sftp.SftpException;

import com.jscape.inet.sftp.events.SftpAdapter;

import com.jscape.inet.ssh.util.SshParameters;

public class SFTPFileDeleter extends SftpAdapter {

static String hostName = ServerProperties.getProperty("test.ftp.hostname");

static String username = ServerProperties.getProperty("test.ftp.login");

static String password = ServerProperties.getProperty("test.ftp.password");

static String directory = ServerProperties.getProperty("test.ftp.directory");

private static Sftp sftp;

private static org.apache.log4j.Logger log = Logger.getLogger(SFTPFileDeleter.class);

public static boolean deleteDir(List path) throws SftpException {

Boolean flag = false;

log.info("------------------------ file(s) delete started ------------------------");

sftp = new Sftp(new SshParameters(hostName, username, password));

sftp.connect();

sftp.setDir(directory);

for (String eachOne : path) {

if (!sftp.getDirListingAsString(eachOne).equals("")){

log.info(" ------ Deleted Folder/Scenario Name: " + eachOne);

//log.info(" ------ check file path: " + directory+eachOne);

//System.out.println(directory+eachOne);

sftp.deleteDir(directory+eachOne, true);

flag = true;

}

}

sftp.disconnect();

log.info("------------------------ file(s) delete finished -----------------------");

return flag;

}

// open connection to the remote server.

public static void openConnection() throws SftpException {

sftp.connect();

}

// disconnect from the remote server.

public static void closeConnection() {

sftp.disconnect();

}

}

and this is the error I got, so jscape sftp will not work for me.

2014-11-29 09:00:04 ERROR MainEntry:47 - There was error and message is java.lang.RuntimeException: Your Secure FTP Factory license expired on Sun Nov 23 00:31:21 CST 2014. Please v

isit http://www.jscape.com to purchase a licensed copy.

2014-11-29 09:00:04 ERROR MainEntry:48 - There was error and stack-trace is [Ljava.lang.StackTraceElement;@fdb00d

any help is much appreciated. Asking here if anybody know other libraries that does delete non-empty folder.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值