You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
225 lines
7.8 KiB
225 lines
7.8 KiB
<template>
|
|
<view class="content">
|
|
<button type="primary" @click="connectFtpServer()">FTP连接</button>
|
|
<button type="primary" @click="ftpUploadFiles()">FTP上传文件夹</button>
|
|
<button type="primary" @click="ftpCreatNewDirectory()">FTP新建文件夹</button>
|
|
<button type="primary" @click="ftpUploadFile()">FTP上传文件</button>
|
|
<button type="primary" @click="ftpDownloadSingleFile()">FTP单个文件下载</button>
|
|
<button type="primary" @click="ftpLoopServerPath()">获取目录</button>
|
|
<button type="primary" @click="ftpDeleteServerFiles()">删除文件</button>
|
|
<button type="primary" @click="ftpDeleteServerFilesWithoutDirectory()">删除文件夹下面文件保留文件夹</button>
|
|
<button type="primary" @click="closeFTPConnect()">FTP断开连接</button>
|
|
|
|
<button type="primary" style="margin-top: 16px;" @click="connectFtpsServer()">FTPS连接</button>
|
|
<button type="primary" @click="ftpsUploadFiles()">FTPS上传文件夹</button>
|
|
<button type="primary" @click="ftpsCreatNewDirectory()">FTPS新建文件夹</button>
|
|
<button type="primary" @click="ftpsUploadFile()">FTPS上传文件</button>
|
|
<button type="primary" @click="ftpsDownloadSingleFile()">FTPS单个文件下载</button>
|
|
<button type="primary" @click="ftpsLoopServerPath()">ftps获取目录</button>
|
|
<button type="primary" @click="ftpsDeleteServerFiles()">ftps删除文件</button>
|
|
<button type="primary" @click="ftpsDeleteServerFilesWithoutDirectory()">ftps删除文件夹下面文件保留文件夹</button>
|
|
<button type="primary" @click="closeFTPSConnect()">FTPS断开连接</button>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
var FTP = uni.requireNativePlugin('Zhimi-FTP-Module');
|
|
export default {
|
|
data() {
|
|
return {
|
|
title: 'Hello',
|
|
}
|
|
},
|
|
onLoad() {
|
|
// console.log(plus.io.convertLocalFileSystemURL('ceshi'));
|
|
},
|
|
methods: {
|
|
// FTP连接
|
|
connectFtpServer() {
|
|
//(“服务地址”, 端口, “用户名”,”密码“, 回调 )
|
|
//回调
|
|
//成功 {type : "connect", data : {data : "相应状态码:200 连接是否成功:true 连接是否有效:true}}
|
|
//失败 {type : "connect", data : {"error" : "失败原因"}}
|
|
// "192.168.50.1", 21, "hmgc", "hmgc"
|
|
// "192.168.50.131", 21, "hmftp", "hmftp"
|
|
FTP.connectFtpServer("192.168.50.1", 21, "hmgc", "hmgc", "gbk", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTP-上传文件夹至服务器FTP
|
|
ftpUploadFiles(ftpFwqName) {
|
|
//(“要上传的本地文件绝对路径”, “服务器文件夹名(/htdocs/fileName)”, 回调)
|
|
//回调
|
|
//{type : "upload", data : {path : "本地上传文件地址", status : true/false, msg : "上传完成", error : "失败原因"}}
|
|
// /storage/emulated/0/Download/downladed_rom
|
|
var inputFile = plus.io.convertLocalFileSystemURL('/static')
|
|
console.log('inputFile文件夹', inputFile);
|
|
FTP.ftpUploadFile(inputFile, '/sda1/DDwifi', res => {
|
|
console.log(ftpFwqName, '文件夹-上传成功');
|
|
console.log(res)
|
|
// 下载至安卓手机
|
|
// this.ftpDownloadSingleFile(ftpFwqName)
|
|
})
|
|
},
|
|
// FTP-上传文件至FTP
|
|
ftpUploadFile() {
|
|
var inputFile = plus.io.convertLocalFileSystemURL('/static/logo.png')
|
|
console.log('inputFile文件', inputFile);
|
|
//同上
|
|
FTP.ftpUploadFile(inputFile, '/sda1/deviceNewFile/20240919', res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTP-新建文件夹至FTP
|
|
ftpCreatNewDirectory() {
|
|
let ftpFwq = 0
|
|
FTP.ftpCreatNewDirectory("/sda1/DDwifi", 'newDirectory', res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTP-单个文件下载至安卓机
|
|
ftpDownloadSingleFile(ftpFwqName) {
|
|
//("要下载到本地文件夹的绝对路径", "要下载的服务器上文件的绝对路径", 回调)
|
|
//回调
|
|
//{type : download, data : {status : true/false, name : "下载的文件名", errpr : "失败原因"}}
|
|
// var inputFile = plus.io.convertLocalFileSystemURL('/static')
|
|
var outputFile = plus.io.convertLocalFileSystemURL('_doc')
|
|
console.log(outputFile);
|
|
FTP.ftpDownloadSingleFile(outputFile, '/sda1/logicDelete/logo.png', res => {
|
|
// console.log(ftpFwqName,下载成功);
|
|
console.log(res)
|
|
})
|
|
},
|
|
// 获取FTP服务器目录
|
|
ftpLoopServerPath() {
|
|
//("获取服务器目录下文件,空白为根目录", 回调)
|
|
//回调
|
|
//成功 {type : getFileInfo, data : [{name : "地址", size : 文件大小单位字节, time : “修改时间”}]}
|
|
//失败 {type : "error", data : "失败原因"}
|
|
FTP.ftpLoopServerPath("/sda1/DDwifi", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// 删除FTP服务器文件
|
|
ftpDeleteServerFiles() {
|
|
//("要删除的文件夹或文件地址", 回调)
|
|
//回调
|
|
//{type : delete, data : {msg : "删除文件/删除文件夹(ps:先删除文件夹里面的文件再删文件夹)", data : "文件名", status : true/false, error : "失败原因"}}
|
|
FTP.ftpDeleteServerFiles('/sda1/DDwifi/logo.png', res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// 删除FTP文件夹下面文件保留文件夹
|
|
ftpDeleteServerFilesWithoutDirectory() {
|
|
//同上,不会删除指定文件夹
|
|
FTP.ftpDeleteServerFilesWithoutDirectory("/sda1/DDwifi", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTP断开连接
|
|
closeFTPConnect() {
|
|
console.log('点到了!!!!');
|
|
//失败有回调,成功没有回调
|
|
FTP.closeFTPConnect(res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
|
|
// ----------ftps----------
|
|
|
|
// FTPS连接
|
|
connectFtpsServer() {
|
|
FTP.connectFtpsServer("192.168.0.8", 21, "hmftp", "hmftp", "gbk", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTPS上传文件夹至服务器
|
|
ftpsUploadFiles() {
|
|
var inputFile = plus.io.convertLocalFileSystemURL('/static')
|
|
console.log('inputFile文件夹', inputFile);
|
|
FTP.ftpsUploadFile(inputFile, "/sda1", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTPS上传文件
|
|
ftpsUploadFile() {
|
|
var inputFile = plus.io.convertLocalFileSystemURL('/static/ceshi.txt')
|
|
FTP.ftpsUploadFile(inputFile, "/sda1", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTPS新建文件夹
|
|
ftpsCreatNewDirectory() {
|
|
FTP.ftpsCreatNewDirectory("/sda1", "newDirectory", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTPS单个文件下载
|
|
ftpsDownloadSingleFile() {
|
|
var outputFile = plus.io.convertLocalFileSystemURL('_doc')
|
|
console.log('outputFile', outputFile);
|
|
FTP.ftpsDownloadSingleFile(outputFile, "/sda1/ceshi.txt", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// 获取FTPS服务器目录
|
|
ftpsLoopServerPath() {
|
|
FTP.ftpsLoopServerPath("/sda1", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// 删除FTPS服务器文件
|
|
ftpsDeleteServerFiles() {
|
|
//("要删除的文件夹或文件地址", 回调)
|
|
//回调
|
|
//{type : delete, data : {msg : "删除文件/删除文件夹(ps:先删除文件夹里面的文件再删文件夹)", data : "文件名", status : true/false, error : "失败原因"}}
|
|
FTP.ftpsDeleteServerFiles('/sda1/ceshi.txt', res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// 删除FTPS文件夹下面文件保留文件夹
|
|
ftpsDeleteServerFilesWithoutDirectory() {
|
|
//同上,不会删除指定文件夹
|
|
FTP.ftpsDeleteServerFilesWithoutDirectory("/sda1", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTPS断开连接
|
|
closeFTPSConnect() {
|
|
console.log('点到了!!!!');
|
|
FTP.closeFTPSConnect(res => {
|
|
console.log('点到了进来了!!!!');
|
|
console.log(res)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.content {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.logo {
|
|
height: 200rpx;
|
|
width: 200rpx;
|
|
margin-top: 200rpx;
|
|
margin-left: auto;
|
|
margin-right: auto;
|
|
margin-bottom: 50rpx;
|
|
}
|
|
|
|
.text-area {
|
|
display: flex;
|
|
justify-content: center;
|
|
}
|
|
|
|
.title {
|
|
font-size: 36rpx;
|
|
color: #8f8f94;
|
|
}
|
|
</style>
|