Git Product home page Git Product logo

any-file's Introduction

Any-File

Node.js library to copy files between several storage sources (ftp, http/https, s3, ssh, local, ...)

Getting Started

Please, follow next instructions to get a working copy of the project up and running on your local machine for development and testing purposes. This is an unstable release. Please, don't use in production environments.

Prerequisities

You need to install nodejs >= 5.8.0 on your machine:

sudo apt-get install nodejs

Probably, library will work with older nodejs versions.

Installing

Please, execute next command to install package

npm install any-file

After that, include the module in your code:

var AnyFile = require('any-file');

Running the tests

To run tests, please execute

make test

All test use public files shared on internet. So, you have to find no problems when testing.

Samples

This module allow to copy files between different storage systems.

All queries begin with calling function from to define source file to copy

from("protocol://username:password@server/path/to/file")

and define destination with method to

to("protocol://username:password@server/path/to/file", callback)

Next protocols are accepted by the library:

  • ftp
  • http, https (only download)
  • scp
  • s3
  • local file system

Additionally, if no protocol schema is defined, local system is assumed.

You can compress and uncompress your files in all operations. Next are supported compression formats: zip, gzip. Please, take in consideration that some zip files could have wrong headers. In those cases, file will be renamed to final extension only.

Next sources are accepted by the library:

You can copy ftp file to local file system

var af = new AnyFile();
var fromFile ="ftp://anonymous:miemail%[email protected]/100KB.zip";
var toFile = "100KB.zip";
af.from(fromFile).to(toFile, function(err, res) {
	if (res) {
		console.log("File copied!");
	} else {
		console.log("File not copied!");
	}
});

Or http file with needed auth to local file system

var af = new AnyFile();
var fromFile = "http://anonymous:miemail%[email protected]/100KB.zip";
var toFile = "100KB.zip";
af.from(fromFile).to(toFile, function(err, res) {
	if (res) {
		console.log("File copied!");
	} else {
		console.log("File not copied!");
	}
});

Or copy from sftp to s3

var af = new AnyFile();
var fromFile = "sftp://demo:[email protected]:/readme.txt";
var toFile = "s3://AKIAIZHM3T2QFIRSVQ5A:[email protected]/any-file-us/readme.txt";
af.from(fromFile).to(toFile, function(err, res) {
	if (res) {
		console.log("File copied!");
	} else {
		console.log("File not copied!");
	}
});

Or copy from sftp to s3 gzipped file

var af = new AnyFile();
var fromFile = "sftp://demo:[email protected]:/readme.txt";
var toFile = "s3://AKIAIZHM3T2QFIRSVQ5A:[email protected]/any-file-us/readme.txt.gz";
af.from(fromFile).to(toFile, function(err, res) {
	if (res) {
		console.log("File copied!");
	} else {
		console.log("File not copied!");
	}
});

You can find more code samples on samples folder using accepted protocols (http, ftp, s3, scp and local). Please, check it out.

Debugging

You can debug the library this way

DEBUG=app node youfile.js

This will show debugging messages on console.

Todo

On future releases, next features will be added:

  • events (start, progress, end, error) instead of callbacks

Contributions

Please, feel free to send pull requests or comments to the project. Contributions are welcome!

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Miquel Colomer - Initial work - mcolomer

See also the list of contributors who participated in this project.

Who is using this repo?

Please, let me know if you are using this repository in a production environment. Next sites use this module:

  • uProc - Data quality service with a huge catalog to Normalize, Validate, Enrich and Deduplicate your data

License

This project is licensed under the Apache License - see the LICENSE file for details

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.