| | |
| | | //OutputStream os = new FileOutputStream(localFile); |
| | | //ftpClient.retrieveFile(fileName, os); os.close(); |
| | | |
| | | |
| | | // 第二种方式下载:将输入流转成字节,再生成文件,这种方式方便将字节数组直接返回给前台jsp页面 |
| | | byte[] input2byte = input2byte(retrieveFileStream); |
| | | byte2File(input2byte, localPath, fileName); |
| | |
| | | return result; |
| | | } |
| | | // 切换到上传目录 |
| | | if (!ftpClient.changeWorkingDirectory(basePath + filePath)) { |
| | | if (!ftpClient.changeWorkingDirectory(basePath +"/"+ filePath)) { |
| | | // 如果目录不存在创建目录 |
| | | String[] dirs = filePath.split("/"); |
| | | String tempPath = basePath; |
| | | String tempPath = ""; |
| | | for (String dir : dirs) { |
| | | if (null == dir || "".equals(dir)) |
| | | if (null == dir || "".equals(dir)) { |
| | | continue; |
| | | } |
| | | tempPath += "/" + dir; |
| | | if (!ftpClient.changeWorkingDirectory(tempPath)) { |
| | | if (!ftpClient.makeDirectory(tempPath)) { |
| | |
| | | LOCAL_CHARSET = "UTF-8"; |
| | | } |
| | | ftpClient.setControlEncoding(LOCAL_CHARSET); |
| | | ftpClient.enterLocalPassiveMode();// 设置被动模式 |
| | | ftpClient.setFileType(FTP.BINARY_FILE_TYPE);// 设置传输的模式 |
| | | // 设置被动模式 |
| | | ftpClient.enterLocalPassiveMode(); |
| | | // 设置传输的模式 |
| | | ftpClient.setFileType(FTP.BINARY_FILE_TYPE); |
| | | // 上传文件 |
| | | filename = new String(filename.getBytes(LOCAL_CHARSET), SERVER_CHARSET); |
| | | if (!ftpClient.storeFile(filename, input)) { |
| | |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "q"+response1+".json", in1); |
| | | FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpBasePath, ftpFilePath, "q"+response1+".json", in1); |
| | | MysqlCenlint.deletess("q"+response1+".json"); |
| | | } |
| | | |
| | | /** |
| | | * 执行sql 上传 |
| | | * @param s1 sql |
| | | */ |
| | | public static void sqlFileClear(String s1){ |
| | | String json1 = JSON.toJSONString(s1); |
| | | String response1 = String.valueOf((new Date()).getTime()); |
| | | OutJson.createJsonFile(json1, localPath, "w"+response1); |
| | | FileInputStream in1 = null; |
| | | try { |
| | | in1 = new FileInputStream(new File(localPath + "w"+response1+".json")); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpBasePath, "/", "w"+response1+".json", in1); |
| | | MysqlCenlint.deletess("w"+response1+".json"); |
| | | } |
| | | |
| | | } |