@kingfang007/react-native-ftp-client
v1.1.7
Published
FTP client library for android and ios
Downloads
24
Readme
react-native-ftp-client
A ftp client library for react native Thanks for react-native-ftp. Get inspired from it, but almost rewrite every corner.
support three operations
- list ftp dir.
- upload file to ftp.
- download file from ftp.
- remove file or dir from ftp.
NO session, which means treating each operation as a session.
Therefore, it is easier to use for javascript client even introduce some overhead on login and logout.
Limit
the download operation depends on the ftp server support size cmd
Example
const downloadFileFrom = async (ftpHost, remote_file_path) => {
FTP.setup({
ip_address: ftpHost,
port: 21,
username: 'anonymous',
password: 'guest',
}); //Setup host
const localPath = 'local file path';
try {
let currentToken = '';
const subscription = FTP.addProgressListener(({token, percentage}) => {
if (percentage === 0) {
//record token
currentToken = token;
}
if (token !== currentToken) {
//ignore
} else {
//show percentage. it is a integer
if (percentage >= 100) {
//finish download
}
}
});
await FTP.downloadFile(localPath, remote_file_path);
//continue after download finish
} catch (error) {
if(error.message === FTP.ERROR_MESSAGE_CANCELLED){
//the download is cancelled
}
//other error
}
};