|
@@ -1,4 +1,4 @@
|
|
|
-package ftp;
|
|
|
|
|
|
|
+package com.primeton.damp.fileclient;
|
|
|
|
|
|
|
|
import org.apache.commons.net.ftp.FTPClient;
|
|
import org.apache.commons.net.ftp.FTPClient;
|
|
|
import org.apache.commons.net.ftp.FTPFile;
|
|
import org.apache.commons.net.ftp.FTPFile;
|
|
@@ -21,7 +21,7 @@ import java.util.stream.Collectors;
|
|
|
/**
|
|
/**
|
|
|
* Created by hadoop on 2018/8/9.
|
|
* Created by hadoop on 2018/8/9.
|
|
|
*/
|
|
*/
|
|
|
-public class FtpClientHandler implements P11ClientHandler {
|
|
|
|
|
|
|
+public class FtpClientHandler implements X11ClientHandler {
|
|
|
|
|
|
|
|
protected static Logger logger = LoggerFactory.getLogger("FtpClientHandler");
|
|
protected static Logger logger = LoggerFactory.getLogger("FtpClientHandler");
|
|
|
|
|
|
|
@@ -166,8 +166,8 @@ public class FtpClientHandler implements P11ClientHandler {
|
|
|
@Override
|
|
@Override
|
|
|
public boolean exists(String path) {
|
|
public boolean exists(String path) {
|
|
|
try {
|
|
try {
|
|
|
- FTPFile mdtmFile = ftpClient.mlistFile(path);
|
|
|
|
|
- return mdtmFile != null;
|
|
|
|
|
|
|
+ final FTPFile ftpFile = ftpClient.mdtmFile(path);
|
|
|
|
|
+ return ftpFile != null && ftpFile.isValid();
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
|
logger.error(e.getMessage());
|
|
logger.error(e.getMessage());
|
|
|
}
|
|
}
|
|
@@ -187,7 +187,7 @@ public class FtpClientHandler implements P11ClientHandler {
|
|
|
if(existsDir(parentPath.toString())){
|
|
if(existsDir(parentPath.toString())){
|
|
|
return mkdir(path1.toString()); // 创建当前文件夹
|
|
return mkdir(path1.toString()); // 创建当前文件夹
|
|
|
} else {
|
|
} else {
|
|
|
- if(mkdirs(parentPath.toString())) { // 创建父级目录
|
|
|
|
|
|
|
+ if("/".equals(parentPath.toString()) || mkdirs(parentPath.toString())) { // 创建父级目录
|
|
|
return mkdir(path1.toString()); // 创建当前文件夹
|
|
return mkdir(path1.toString()); // 创建当前文件夹
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -237,13 +237,13 @@ public class FtpClientHandler implements P11ClientHandler {
|
|
|
//test
|
|
//test
|
|
|
public static void main(String[] args) throws IOException {
|
|
public static void main(String[] args) throws IOException {
|
|
|
Properties map = new Properties();
|
|
Properties map = new Properties();
|
|
|
- String host = "localhost";
|
|
|
|
|
|
|
+ String host = "192.168.30.143";
|
|
|
int port = 2121;
|
|
int port = 2121;
|
|
|
String username = "admin";
|
|
String username = "admin";
|
|
|
- String password = "admin";
|
|
|
|
|
|
|
+ String password = "primeton000000";
|
|
|
FtpClientHandler handler = new FtpClientHandler(host, port, username, password, map);
|
|
FtpClientHandler handler = new FtpClientHandler(host, port, username, password, map);
|
|
|
// handler.changeWorkingDirectory("/sms");
|
|
// handler.changeWorkingDirectory("/sms");
|
|
|
- List<Path> result = handler.getChildren("/ta-lib");
|
|
|
|
|
|
|
+ List<Path> result = handler.getChildren("/DAMP");
|
|
|
for (Path ftpFile : result) {
|
|
for (Path ftpFile : result) {
|
|
|
System.out.println(ftpFile.toString());
|
|
System.out.println(ftpFile.toString());
|
|
|
}
|
|
}
|
|
@@ -255,6 +255,7 @@ public class FtpClientHandler implements P11ClientHandler {
|
|
|
out.close();
|
|
out.close();
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
|
|
+ System.out.println(handler.exists("/"));
|
|
|
System.out.println(handler.exists("/hello.txt"));
|
|
System.out.println(handler.exists("/hello.txt"));
|
|
|
System.out.println(handler.exists("/example_data_1225"));
|
|
System.out.println(handler.exists("/example_data_1225"));
|
|
|
System.out.println(handler.exists("/world/example_data_1225"));
|
|
System.out.println(handler.exists("/world/example_data_1225"));
|