| | |
| | | import org.apache.commons.lang.StringUtils; |
| | | |
| | | import java.io.*; |
| | | import java.text.ParseException; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.LinkedList; |
| | |
| | | return rsList; |
| | | } |
| | | |
| | | public void deleteDir(String dirName) throws IOException, FTPException { |
| | | public void deleteDir(String dirName) throws IOException, FTPException, ParseException { |
| | | FTPClient client = ftp; |
| | | String[] dir = client.dir(dirName, true); |
| | | for (String subDirName : dir) { |
| | | |
| | | //String[] dir = client.dir(dirName, true); |
| | | FTPFile[] ftpFiles = client.dirDetails(dirName); |
| | | for (FTPFile ftpFile : ftpFiles) { |
| | | if(ftpFile.isDir()){ |
| | | deleteDir(dirName+"/"+ftpFile.getName()); |
| | | }else{ |
| | | client.delete(dirName+"/"+ftpFile.getName()); |
| | | } |
| | | } |
| | | /*for (String subDirName : dir) { |
| | | String name = subDirName.substring(subDirName.lastIndexOf(" ") + 1); |
| | | if(subDirName.contains("<DIR>")){ //文件夹 |
| | | //name = new String(name.getBytes(StandardCharsets.ISO_8859_1),"GBK"); |
| | |
| | | //name = new String(name.getBytes(StandardCharsets.ISO_8859_1),"GBK"); |
| | | client.delete(dirName+"/"+name); |
| | | } |
| | | } |
| | | }*/ |
| | | client.rmdir(dirName); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | try { // 从ftp下载文件 |
| | | FtpHelper ftp = new FtpHelper("192.168.10.80", 21, "lxw", "lxw810412026"); |
| | | //File file = new File("D:\\fileTest\\内阻分析软件-问题反馈-20221031.docx"); |
| | | /*ftp.uploadFile(file, "test/"+"内阻分析软件-问题反馈-20221031.docx"); |
| | | ftp.disconnect();*/ |
| | | List<File> list=ftp.getFileList("D:\\fileTest\\software"); |
| | | if(list!=null&&list.size()>0){ |
| | | for (File file:list) { |
| | | String name=file.getPath().substring(file.getPath().lastIndexOf("software")); |
| | | System.out.println(name); |
| | | String pathName="/"+name.replace("\\","/"); |
| | | ftp.uploadFile(file, pathName); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public String[] getDirList() throws IOException, FTPException { |