0
我试图通过SFTP删除非空文件夹的JSCH,但它没有奏效。SFTP非空文件夹递归删除
这一个工作,但它不是免费的:(我已经过去30天的试用期。我公司拒绝支付他们只是通过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 <String> 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();
}
}
,这是错误我得到了,所以jscape sftp
不会为我工作。
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
任何的帮助深表感谢。在这里询问是否有人知道,它删除非空文件夹其他库。
您可以在http://softwarerecs.stackexchange.com/ – 2014-12-01 16:30:13
问这样的问题了为什么不直接使用jsch试图删除文件夹之前,递归地删除文件夹中的一切吗?获取目录中所有内容的列表并遍历它们。测试每个以查看它是否是文件或目录。如果它是一个目录,请进行递归调用以将其清空并将其删除。如果它是一个文件,只需删除它。 – Rob 2014-12-01 16:33:33
@ jiten-k你在这里寻找什么样的答案?寻找第三方,充分运作的软件的问题在这里是无关紧要的。您发布的代码显然不起作用,因为您的JScape库的许可证已过期。你应该能够以jsch来实现这个,但是你没有提供关于你的jsch尝试的任何细节。 – Kenster 2014-12-01 19:15:11