如何補(bǔ)開發(fā)票
2023-11-07
更新時(shí)間:2023-11-07 09:11:21作者:未知
FTP操作工具類:
public class FTPUtil {private final Logger logger = LoggerFactory.getLogger(FTPUtil.class);private static String encoding = "UTF-8";/** * ftp客戶端 */FTPClient ftpClient;/** * ftp服務(wù)器地址 */private String host;/** * ftp 端口號(hào) 默認(rèn)21 */private int port = 21;/** * ftp服務(wù)器用戶名 */private String username;/** * ftp服務(wù)器密碼 */private String password;/** * ftp遠(yuǎn)程目錄 */private String remoteDir;/** * 本地存儲(chǔ)目錄 */private String localDir;/** * 文件路徑通配符 默認(rèn)列出所有 */private String regEx = "*";/** * 指定要下載的文件名 */private String downloadFileName;public FTPUtil setConfig(String host, String username, String password) {this.host = host;this.username = username;this.password = password;return this;}public FTPUtil setConfig(String host, int port, String username, String password) {this.host = host;this.port = port;this.username = username;this.password = password;return this;}private void connectServer() throws Exception {if (this.ftpClient == null) {this.ftpClient = new FTPClient();}// 設(shè)置超時(shí)時(shí)間this.ftpClient.setConnectTimeout(30000);try {// 1、連接服務(wù)器if (!this.ftpClient.isConnected()) {// 如果采用默認(rèn)端口,可以使用client.connect(host)的方式直接連接FTP服務(wù)器this.ftpClient.connect(this.host, this.port);// 登錄this.ftpClient.login(this.username, this.password);// 獲取ftp登錄應(yīng)答碼int reply = this.ftpClient.getReplyCode();// 驗(yàn)證是否登陸成功if (!FTPReply.isPositiveCompletion(reply)) {logger.info("未連接到FTP,用戶名或密碼錯(cuò)誤。");this.ftpClient.disconnect();throw new RuntimeException("未連接到FTP,用戶名或密碼錯(cuò)誤。");} else {logger.info("FTP連接成功。IP:" host "PORT:" port);}// 2、設(shè)置連接屬性this.ftpClient.setControlEncoding(FTPUtil.encoding);// 設(shè)置以二進(jìn)制方式傳輸this.ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);this.ftpClient.enterLocalPassiveMode();}} catch (Exception e) {try {this.ftpClient.disconnect();} catch (IOException e1) {}logger.error("連接FTP服務(wù)器出現(xiàn)異常,參數(shù):ip=" this.host ",port=" this.port ",user=" this.username ",password=" this.password);}}public List