| | |
| | | package com.whyc.dto; |
| | | |
| | | import com.whyc.constant.YamlProperties; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.net.ftp.FTPClient; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | import java.io.IOException; |
| | | |
| | | @Component |
| | | @Slf4j |
| | | public class FTPClientUtil { |
| | | |
| | | public static FTPClient connect(){ |
| | |
| | | ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); |
| | | final int bufferSize = 20*1024 * 1024; |
| | | ftpClient.setBufferSize(bufferSize); |
| | | |
| | | log.info("---------------FTP Client 连接成功------------------"); |
| | | return ftpClient; |
| | | |
| | | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | log.error("---------------FTP Client 连接失败:"+e.toString()+"------------------"); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | ftpClient.storeFile(descFilePath, fileInputStream); |
| | | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | log.error("---------------文件"+ originalFile.getName() +" FTP 传输异常:"+e.toString()+"------------------"); |
| | | } finally { |
| | | try { |
| | | fileInputStream.close(); |
| | |
| | | ftpClient.disconnect(); |
| | | } |
| | | } catch (IOException ex) { |
| | | ex.printStackTrace(); |
| | | log.error("---------------关流异常:"+ex.toString()+"------------------"); |
| | | } |
| | | } |
| | | } |