wuxw
2024-01-09 05a7f827b7ff555f88982e2dcfb45c2ef5a34a54
java110-core/src/main/java/com/java110/core/client/FtpUploadTemplate.java
@@ -172,7 +172,7 @@
        String ftpPath = "/";
        if(fileName.contains("/")){
            ftpPath = fileName.substring(0,fileName.lastIndexOf("/"));
            ftpPath = fileName.substring(0,fileName.lastIndexOf("/")+1);
        }
        try {
@@ -188,6 +188,7 @@
            mkDir(ftpClient, ftpPath);// 创建目录
            // 设置上传目录 must
            ftpClient.changeWorkingDirectory(ftpPath);
            if (FTPReply.isPositiveCompletion(ftpClient.sendCommand("OPTS UTF8", "ON"))) {// 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码,否则就使用本地编码(GBK).
                LOCAL_CHARSET = "UTF-8";
            }
@@ -200,7 +201,7 @@
                System.out.println("this file exist ftp");
                ftpClient.deleteFile(fs[0].getName());
            }
            boolean saveFlag = ftpClient.storeFile(fileName, inputStream);
            boolean saveFlag = ftpClient.storeFile("/"+fileName, inputStream);
            if (!saveFlag) {
                throw new IllegalArgumentException("存储文件失败");
            }
@@ -228,6 +229,8 @@
                ftpClient.connect(server, port);
            }
            ftpClient.login(userName, userPassword);
            ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
            ftpClient.enterLocalPassiveMode();
            if (ftpClient != null) {
                String f = new String(
@@ -418,7 +421,7 @@
                ftpClient.disconnect();
            }
            String f = new String(
                    (fileName).getBytes("GBK"),
                    ("/"+fileName).getBytes("GBK"),
                    FTP.DEFAULT_CONTROL_ENCODING);
            is = ftpClient.retrieveFileStream(f);// 获取远程ftp上指定文件的InputStream
            if (null == is) {
@@ -429,11 +432,11 @@
            logger.error("ftp通过文件名称获取远程文件流", e);
        } finally {
            try {
                //closeConnect(ftpClient);
                closeConnect(ftpClient);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
        return is;
    }
}