Actually, I want to get the files with directory structure uploaded on FTP server using React-native.
I have tried to find libraries but I didn't find anything related to it.
So can you please help me with this problem?
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>
);
}
}
Here is the sample i have tried but i got error while impoting 'react-native-ftp'. I got error "Could not find declaration for module 'react-native-ftp'".
The error you encounter is because of react-native-ftp functions are not available on ios - they are not implemented. You need to fork the repo and implement them to work with ios too.
and then:
You can download a file like below using react-native-ftp:
FTP.downloadFile("./nameOfFileToBeDownloaded","localPathWhereItWillBeSaved")
.then(result=>console.log(result))
.catch(error=>alert(error))
Or upload with uploadFile:
FTP.uploadFile("./nameOfFileToBeUploaded","remotePathWhereItWillBeSaved")
.then(result=>console.log(result))
.catch(error=>alert(error))
If you want entire folder, you can zip it first with react-native-zip-archive and the upload just the zip.