6309\u5728\u670D\u52A1\u7AEF\u7684\u8DEF\u5F84\u5728\u6307\u5B9A\u672C\u5730\u8DEF\u5F84\u4E0B\u521B\u5EFA\u60F3\u5BF9\u5E94\u7684\u8DEF\u5F84\u548C\u6587\u4EF6 * @param localPath * \u672C\u5730\u8DEF\u5F84 * @return * @throws Exception */ public static boolean downloadToLocal2(String filename, String localPath) throws Exception { List
list=listNames(); OutputStream out; try{ for(Iterator
it=list.iterator();it.hasNext();){ String filepath=it.next(); if(filepath.contains(filename)){ String remoteFilePath=filepath.substring(1, filepath.length()); File file=new File(localPath+remoteFilePath); new File(file.getParent()).mkdirs(); out= new FileOutputStream(localPath+remoteFilePath); getFTPClient().retrieveFile(filepath, out); // \u4E0B\u8F7D out.close(); } } return true; }catch (Exception e) { return false; } } /** * @description \u521B\u5EFA\u8FDC\u7A0B\u76EE\u5F55\u5141\u8BB8\u521B\u5EFA\u591A\u7EA7\u76EE\u5F55 * @param remoteDir \u8FDC\u7A0B\u76EE\u5F55 * @return * @throws SocketException * @throws IOException * @throws FTPClientException */ public static boolean mkdirs(String remoteDir) throws SocketException, IOException, FTPClientException{ String[] dirs=remoteDir.split("/"); String remotePath="."; for(String dir:dirs){ if(!dir.equals(".")&&null!=dir){ remotePath=remotePath+File.separator+dir+File.separator; boolean result=getFTPClient().makeDirectory(remotePath); if(!result){ return result; } } } return true; } }
|