npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-ftp-service

v0.2.1

Published

phong dev

Readme

react-native-ftp-service

Thư viện FTP service cho React Native

Yêu cầu hệ thống

  • Node.js >= 16
  • React Native >= 0.70.0
  • iOS: Xcode >= 14.0
  • Android: Android Studio với Android SDK

Cài đặt

1. Cài đặt thư viện

# Sử dụng npm
npm install react-native-ftp-service

# Hoặc sử dụng yarn
yarn add react-native-ftp-service

2. Cấu hình iOS

cd ios && pod install

3. Cấu hình Android

Đảm bảo rằng module FtpService được đăng ký trong MainApplication.java:

package com.yourapp;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.defaults.DefaultReactNativeHost;
import com.facebook.soloader.SoLoader;
import java.util.List;

// Thêm import này
import com.ftpservice.FtpServicePackage;

public class MainApplication extends Application implements ReactApplication {
  private final ReactNativeHost mReactNativeHost =
      new DefaultReactNativeHost(this) {
        @Override
        protected List<ReactPackage> getPackages() {
          @SuppressWarnings("UnnecessaryLocalVariable")
          List<ReactPackage> packages = new PackageList(this).getPackages();

          // Thêm dòng này để đăng ký FtpServicePackage
          packages.add(new FtpServicePackage());

          return packages;
        }

        // Còn lại của MainApplication.java
      };
}

Lưu ý: Nếu bạn đang sử dụng React Native CLI, có thể react-native link sẽ tự động thêm package này. Kiểm tra MainApplication.java để chắc chắn.

Sử dụng

1. Kết nối FTP

import FtpService from 'react-native-ftp-service';

// Kết nối đến máy chủ FTP
const connect = async () => {
  try {
    await FtpService.setup(host, port, username, password);
    console.log('Kết nối thành công');
  } catch (error) {
    console.error('Lỗi kết nối:', error);
  }
};

2. Liệt kê files và thư mục

// Liệt kê files trong thư mục
const listFiles = async (path = '/') => {
  try {
    const files = await FtpService.listFiles(path);
    console.log('Danh sách files:', files);
  } catch (error) {
    console.error('Lỗi liệt kê files:', error);
  }
};

3. Tải file lên

// Tải file lên server
const uploadFile = async (localPath, remotePath) => {
  try {
    const result = await FtpService.uploadFile(localPath, remotePath);
    console.log('Tải lên thành công:', result);
  } catch (error) {
    console.error('Lỗi tải lên:', error);
  }
};

4. Tải file xuống

// Tải file từ server
const downloadFile = async (remotePath, localPath) => {
  try {
    const result = await FtpService.downloadFile(remotePath, localPath);
    console.log('Tải xuống thành công:', result);
  } catch (error) {
    console.error('Lỗi tải xuống:', error);
  }
};

5. Tạo thư mục mới

// Tạo thư mục mới
const createDirectory = async (path) => {
  try {
    await FtpService.makeDirectory(path);
    console.log('Tạo thư mục thành công');
  } catch (error) {
    console.error('Lỗi tạo thư mục:', error);
  }
};

6. Xóa file hoặc thư mục

// Xóa file
const deleteFile = async (path) => {
  try {
    await FtpService.deleteFile(path);
    console.log('Xóa file thành công');
  } catch (error) {
    console.error('Lỗi xóa file:', error);
  }
};

// Xóa thư mục
const deleteDirectory = async (path) => {
  try {
    await FtpService.deleteDirectory(path);
    console.log('Xóa thư mục thành công');
  } catch (error) {
    console.error('Lỗi xóa thư mục:', error);
  }
};

7. Đổi tên file hoặc thư mục

// Đổi tên file hoặc thư mục
const rename = async (oldPath, newPath) => {
  try {
    await FtpService.rename(oldPath, newPath);
    console.log('Đổi tên thành công');
  } catch (error) {
    console.error('Lỗi đổi tên:', error);
  }
};

8. Theo dõi tiến trình

// Thêm listener theo dõi tiến trình
const removeListener = FtpService.addProgressListener((info) => {
  console.log('Tiến trình:', info.percentage);
});

// Xóa listener khi không cần thiết
removeListener();

9. Tạm dừng và tiếp tục tác vụ

// Tạo token để theo dõi tác vụ
const token = FtpService.makeProgressToken(localPath, remotePath);

// Tạm dừng tác vụ
const pauseTask = async () => {
  try {
    await FtpService.cancelUploadFile(token);
    console.log('Đã tạm dừng tác vụ');
  } catch (error) {
    console.error('Lỗi tạm dừng:', error);
  }
};

Ví dụ đầy đủ

Bạn có thể xem ví dụ đầy đủ trong thư mục example/ của dự án.

Đóng góp

Xem hướng dẫn đóng góp tại CONTRIBUTING.md để tìm hiểu cách đóng góp vào repository và quy trình phát triển.

Giấy phép

MIT


Được tạo bởi create-react-native-library