FTP所有操作集成成功

This commit is contained in:
2018-05-09 21:54:38 +08:00
parent 3d5a814a5c
commit f56c7ce02a
5 changed files with 51 additions and 35 deletions

View File

@@ -263,6 +263,7 @@ public class FtpOperationUtil {
*/
public boolean isExistsFile(String path, String fileName) throws IOException {
boolean flagChange = false;
if (path != null && path.length() != 0) {
String[] dirs = path.split("/");
ftpClient.changeWorkingDirectory("/");
@@ -277,8 +278,9 @@ public class FtpOperationUtil {
try {
fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
FTPFile[] file = ftpClient.listFiles(fileName);
return file.length > 0 ? true : false;
return file.length > 0;
} catch (IOException e) {
e.getMessage();
e.printStackTrace();
return false;
}
@@ -325,6 +327,16 @@ public class FtpOperationUtil {
return ftpClient.listNames();
}
public String[] list(String path) throws IOException {
String[] dirs = path.split("/");
ftpClient.changeWorkingDirectory("/");
for (int i = 1; dirs != null && i < dirs.length; i++) {
dirs[i] = new String(dirs[i].getBytes("UTF-8"), "iso-8859-1");
ftpClient.changeWorkingDirectory(dirs[i]);
}
return ftpClient.listNames();
}
/**
* 删除服务器上的文件
*
@@ -522,6 +534,16 @@ public class FtpOperationUtil {
return ftpClient.retrieveFileStream(sourceFileName);
}
public InputStream downFile(String path,String sourceFileName) throws IOException {
sourceFileName = new String(sourceFileName.getBytes("UTF-8"), "iso-8859-1");
path = new String(path.getBytes("UTF-8"), "iso-8859-1");
if (path != null && path.length() != 0) {
boolean flagChange = ftpClient.changeWorkingDirectory(path);
System.out.println("【目录切换】" + flagChange);
}
return ftpClient.retrieveFileStream(sourceFileName);
}
public static void main(String[] args) throws Exception {
//testUpload();
//testDownload();