实际上,我想让目录结构的文件上传到FTP服务器上,使用React-本机。
我试着去找图书馆,但没有找到任何与它有关的东西。
所以你能帮我解决这个问题吗?
import React, { Component } from 'react';
import { StyleSheet, View, Button } from 'react-native';
import FTP from 'react-native-ftp';
export default class App extends Component {
onButtonpress() {
FTP.setup("IP", 21) //Setup host
FTP.login("username", "password").then(
(result) => {
FTP.list(".").then(
(result) => {
console.log(result);
}
);
},
(error) => {
alert(error);
}
)
}
render() {
return (
<View >
<Button onPress={this.onButtonpress.bind(this)} title="hi" />
</View>
);
}
}这是我试过的示例,但在输入“react本机-ftp”时出现了错误。我得到错误“找不到模块‘的声明’反应-本机-ftp‘”。
发布于 2019-01-08 14:20:10
您遇到的错误是因为react本机ftp函数在ios上不可用-它们没有实现。您需要分叉回购并实现它们,以便与ios一起工作。
然后:
您可以使用ftp本机ftp下载如下所示的文件:
FTP.downloadFile("./nameOfFileToBeDownloaded","localPathWhereItWillBeSaved")
.then(result=>console.log(result))
.catch(error=>alert(error))或与uploadFile一起上传:
FTP.uploadFile("./nameOfFileToBeUploaded","remotePathWhereItWillBeSaved")
.then(result=>console.log(result))
.catch(error=>alert(error))如果你想要整个文件夹,你可以先用zip本机压缩存档来压缩它,然后上传就可以了。
https://stackoverflow.com/questions/54034473
复制相似问题