pom包引入
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.0.M4</version>
</dependency>
<!-- FTP客戶(hù)端封裝 -->
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>
<!-- 簡(jiǎn)易FTP服務(wù)器 -->
<dependency>
<groupId>org.apache.ftpserver</groupId>
<artifactId>ftpserver-core</artifactId>
<version>1.1.1</version>
</dependency>
public void ftp(){
// ftp 服務(wù)器
BaseUser user = new BaseUser(); // 登陸用戶(hù)
user.setName("username"); // 設(shè)置用戶(hù)名
user.setPassword("123"); // 設(shè)置用戶(hù)密碼
user.setHomeDirectory(screeningFile); // 用戶(hù)目錄
user.setEnabled(true); // 啟用用戶(hù)
user.setAuthorities(ListUtil.of(new WritePermission())); // 設(shè)置用戶(hù)寫(xiě)入權(quán)限
SimpleFtpServer
.create() // 創(chuàng)建ftp服務(wù)
.addUser(user) // 添加用戶(hù)
.setPort(21) // 設(shè)置端口
.start(); // 啟動(dòng)ftp服務(wù)
// ftp客戶(hù)端
Ftp ftp = new Ftp("127.0.0.1", 21, "username", "123");
List<String> ls = ftp.ls("/"); // 遍歷文件
ls.forEach(System.out::println);
String fileSuffix = "pdf";
// 查找文件
File file = FileUtil.findFile("220422144756100006",
"C:\\Users\\Administrator\\Desktop\\10-廠商提供設(shè)備材料(1)\\10-廠商提供設(shè)備材料\\神經(jīng)傳導(dǎo)",
fileSuffix);
// 文件上傳
boolean upload = ftp.upload("/pdf/", file);
System.out.println("/pdf/"+file.getName());
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。