Skip to content

Create an ftp account via rest API and mount data directory to AWSs3 bucket

Notifications You must be signed in to change notification settings

chathunb/ftp-create-aws-s3-mount-rest-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create an FTP account and mount it to AWS s3 with the rest API

This is nodejs API service for creating FTP user accounts on a Linux environment and an FTP data directory will mount on the AWS s3 bucket. Data will sync between the Linux instance and s3 bucket bidirectional. When creating an FTP account user details are also saved on the SQLite database in the project directory and it will help to prevent creating a duplicate entry on the FTP server

Table of Contents

Environment

First you need to set up a Linux environment with the below requirements

FTP-user create bash script

create this group on your Linux instance before running the script

sudo groupadd sftpusers

This Linux bash script ftp-user-create.sh will create the user account on the FTP account and directory on the s3 bucket, finally add the mounting location to the Linux fstab for automatically mount a directory on an instance when it starts. make sure to provide execution permission for the bash script.

For debug/test the bash script you can run it manually with test data

./ftp-user-create.sh user password "" "" s3 bucket-name ap-south-1 1

Prerequisites

For Windows

  • Python 2.7 (for Microsoft build tools)
  • Install Microsoft build tools (to build SQLite using node-gyp)
  • Node-gyp (npm install --global node-gyp)

Usage

  • Run npm install to install dependencies
  • Run npm run start to start the local server
  • Load http://localhost:8000 to test the endpoint. It will display a JSON result {"message":"Ok"}

API Endpoints

To create an FTP account call this rest API with valid data it will create the account and mount it on the s3 bucket check node app logs for errors

POST /api/user/

To create a new user based on POST data (x-www-form-url-encoded)

  • name: User name (ftp user name)
  • password: User password (ftp user password)
  • bucket: S3 Bucket Name

Headers

  • token: security token based on the environment
    default token : SHDXE5EL5E9ED (hardcoded in server.js change it when you deploy )

The success result is:

{
    "message": "success",
    "data": {
        "name": "ftp-user",
        "bucket": "ftp-bucket",
        "path": "ftp-bucket/ftp-user"
    },
    "id": 21
}

The error result is:

{
    "message": "error",
    "error": "User Alrady Exist"
}

Usage

You can use this project to create an FTP account on a Linux server and mount it to AWS s3 specially in some scenarios we have to create FTP accounts in our information systems and provide them to users this is good for that kind of use case

write-your-code-here

Project Status

Project is: completed but has many features to add.

Room for Improvement

Below points can be considered as improvements in this project

Room for improvement:

  • Security improvements ( add some authentication layer )
  • APIs to update the view and delete user accounts
  • Web portal to view details
  • Setup another DBMS
  • Add docker to project

Acknowledgement

Give credit here.

Contact

Created by @chathunbandara - feel free to contact me!

About

Create an ftp account via rest API and mount data directory to AWSs3 bucket

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published