java從ftp伺服器上拉取檔案,並做相應的處理

2021-09-22 01:24:31 字數 1240 閱讀 4073

專案採用的是springboot,依賴管理工具用的是gradle,配置檔案是yml檔案

1.匯入相關ftp需要的jar包

dependencies

3.建立ftp相關的utils

@slf4j

public class ftpfilemanager

// file's path

private string ftproot;

private ftpclient readftp;

private listfiles = new arraylist<>();

private listdonefiles = new arraylist<>();

private listerrorfiles = new arraylist<>();

// fetch files from ftp

public listfetch() throws ioexception catch (ioexception e) finally }}

return this.files;

}public void filedone(file file)

public void fileerror(file file)

public void clean() throws ioexception moved to done:{}", file.getname(), moved);

}for (file file : this.errorfiles) moved to error:{}", file.getname(), moved);

}for (file file : this.files) temp file was not deleted", file.getabsolutepath() + file.getname());}}

}catch(ioexception io) finally

private ftpclient connect() throws ioexception ]", replycode);

throw new ioexception();

}return ftpclient;

} catch (ioexception e) ],causer為:[{}]*****=", e.getmessage(), e.getcause());

throw e;

}}//定義列舉型別,來區分檔案的狀態

enum folder

}

定時自動從FTP伺服器取資料指令碼

開始進入正題 環境需求 某些情況下經常需要向ftp伺服器取檔案,可以用定時任務執行簡單指令碼自動去取相應檔案。一般用法 ftpip位址埠 ftp命令可以通過yum install ftp方式安裝 指令碼示例 示例1.每天凌晨3點定時向ftp伺服器取前一天打包好的檔案。假設檔名格式 google 20...

使用java操作FTP伺服器上的檔案

最近的工作中,需要定時操作ftp伺服器上的檔案,用到了ftpclient 記錄並分享一下使用心得 首先當然是引包 commons net 2.0.jar 這樣你就可以使用ftpclient這個類建立用於連線ftp伺服器的物件了 具體方法見 ftpclient ftpclient new ftpcli...

Linux伺服器上搭建FTP服務

安裝 vsftpd0 使用 yum 安裝 vsftpd yum install vsftpd y啟動 vsftpd0 安裝完成後,啟動 ftp 服務 service vsftpd start啟動後,可以看到系統已經監聽了 21 埠 netstat nltp grep 21修改配置檔案 vsftpd ...