1.0.1 • Published 2 years ago
zc-ftp-service v1.0.1
zc-ftp-service
intruoduce
- zhice teamson company development this module and all right reserved!
- attention ! just suport the spring-ioc framework.
install
npm instlal zc-ftp-service
usage
1.set the configuration file
file path: ${Project}/resource/ZcFtpService.json
basic config:
{
"host":"222.222.222.22",
"port":9022221,
"user":"312342",
"password":"zh3453453enmi345n"
}
2. load ftp module at launch.
const {SpringBoot} = require("spring-ioc")
const {ZcFtpServiceScaner} = require("zc-ftp-service")
new SpringBoot({srcList:["./demo"],moduleList:[ZcFtpServiceScaner]}).run();
3. call in the spring container!
//@SpringBoot
class Application {
//@Autowired
zcFtpService;
async main(){
try{
this.zcFtpService.safeInvoke(async ftp => {
console.log("ftp 主机 登陆成功");
console.log("显示根目录 /");
const datas = await ftp.list("/");
const rootDirName = datas[0].name;
console.log(`根目录名称:${rootDirName}`)
ftp.cwd(rootDirName+"/ftptest")
console.log("进入courware/ftptest目录成功");
const data2s = await ftp.list("");
console.log(data2s)
const uploadDir = "uploadTestDir78";
await ftp.mkdirAndGoto(uploadDir)
console.log(`创建上传目录${uploadDir}成功`);
const uploadInfo = await ftp.put(path.join(__dirname,'uploadTestA.txt'),"uploadTestA.txt")
console.log("文件上传成功",uploadInfo);
ftp.cwd("../")
await ftp.rmdir(uploadDir)
console.log("删除上传目录成功");
})
}catch(e){
await this.zcFtpService.close();
console.log(e)
}
}
}