├── .editorconfig ├── .gitattributes ├── .gitignore ├── .jshintrc ├── .travis.yml ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "curly": true, 6 | "immed": true, 7 | "newcap": true, 8 | "noarg": true, 9 | "undef": true, 10 | "unused": "vars", 11 | "strict": true 12 | } 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - 'iojs' 5 | - '0.12' 6 | - '0.10' 7 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var path = require('path'); 3 | var gutil = require('gulp-util'); 4 | var through = require('through2'); 5 | var assign = require('object-assign'); 6 | var JSFtp = require('jsftp'); 7 | var chalk = require('chalk'); 8 | var plur = require('plur'); 9 | 10 | JSFtp = require('jsftp-mkdirp')(JSFtp); 11 | 12 | module.exports = function (options) { 13 | options = assign({}, options); 14 | options.verbose = process.argv.indexOf('--verbose') !== -1; 15 | 16 | if (options.host === undefined) { 17 | throw new gutil.PluginError('gulp-ftp', '`host` required'); 18 | } 19 | 20 | var fileCount = 0; 21 | var remotePath = options.remotePath || ''; 22 | delete options.remotePath; 23 | 24 | return through.obj(function (file, enc, cb) { 25 | if (file.isNull()) { 26 | cb(null, file); 27 | return; 28 | } 29 | 30 | if (file.isStream()) { 31 | cb(new gutil.PluginError('gulp-ftp', 'Streaming not supported')); 32 | return; 33 | } 34 | 35 | // have to create a new connection for each file otherwise they conflict 36 | var ftp = new JSFtp(options); 37 | 38 | var finalRemotePath = path.join('/', remotePath, file.relative).replace(/\\/g, '/'); 39 | 40 | ftp.mkdirp(path.dirname(finalRemotePath).replace(/\\/g, '/'), function (err) { 41 | if (err) { 42 | cb(new gutil.PluginError('gulp-ftp', err, {fileName: file.path})); 43 | return; 44 | } 45 | 46 | ftp.put(file.contents, finalRemotePath, function (err) { 47 | if (err) { 48 | cb(new gutil.PluginError('gulp-ftp', err, {fileName: file.path})); 49 | return; 50 | } 51 | 52 | fileCount++; 53 | ftp.raw.quit(); 54 | cb(null, file); 55 | }); 56 | }); 57 | 58 | if (options.verbose) { 59 | gutil.log('gulp-ftp:', chalk.green('✔ ') + file.relative); 60 | } 61 | }, function (cb) { 62 | if (fileCount > 0) { 63 | gutil.log('gulp-ftp:', gutil.colors.green(fileCount, plur('file', fileCount), 'uploaded successfully')); 64 | } else { 65 | gutil.log('gulp-ftp:', gutil.colors.yellow('No files uploaded')); 66 | } 67 | 68 | cb(); 69 | }); 70 | }; 71 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Sindre Sorhus (sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-ftp", 3 | "version": "1.1.0", 4 | "description": "Upload files to an FTP-server", 5 | "license": "MIT", 6 | "repository": "sindresorhus/gulp-ftp", 7 | "author": { 8 | "name": "Sindre Sorhus", 9 | "email": "sindresorhus@gmail.com", 10 | "url": "sindresorhus.com" 11 | }, 12 | "engines": { 13 | "node": ">=0.10.0" 14 | }, 15 | "scripts": { 16 | "test": "mocha" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [ 22 | "gulpplugin", 23 | "ftp", 24 | "jsftp", 25 | "file", 26 | "files", 27 | "transfer", 28 | "protocol", 29 | "server", 30 | "client", 31 | "upload", 32 | "deploy", 33 | "deployment" 34 | ], 35 | "dependencies": { 36 | "chalk": "^1.0.0", 37 | "gulp-util": "^3.0.0", 38 | "jsftp": "^1.3.0", 39 | "jsftp-mkdirp": "^1.0.0", 40 | "object-assign": "^4.0.1", 41 | "parents": "^1.0.0", 42 | "plur": "^2.1.0", 43 | "through2": "^2.0.0" 44 | }, 45 | "devDependencies": { 46 | "ftp-test-server": "0.0.2", 47 | "mocha": "*", 48 | "path-exists": "^2.0.0" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # gulp-ftp [![Build Status](https://travis-ci.org/sindresorhus/gulp-ftp.svg?branch=master)](https://travis-ci.org/sindresorhus/gulp-ftp) 2 | 3 | ## Deprecated in favor of [`vinyl-ftp`](https://github.com/morris/vinyl-ftp). 4 | 5 | > Upload files to an FTP-server 6 | 7 | Useful for uploading and deploying things. 8 | 9 | 10 | ## Install 11 | 12 | ``` 13 | $ npm install --save-dev gulp-ftp 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```js 20 | var gulp = require('gulp'); 21 | var gutil = require('gulp-util'); 22 | var ftp = require('gulp-ftp'); 23 | 24 | gulp.task('default', function () { 25 | return gulp.src('src/*') 26 | .pipe(ftp({ 27 | host: 'website.com', 28 | user: 'johndoe', 29 | pass: '1234' 30 | })) 31 | // you need to have some kind of stream after gulp-ftp to make sure it's flushed 32 | // this can be a gulp plugin, gulp.dest, or any kind of stream 33 | // here we use a passthrough stream 34 | .pipe(gutil.noop()); 35 | }); 36 | ``` 37 | 38 | 39 | ## API 40 | 41 | ### ftp(options) 42 | 43 | #### options.host 44 | 45 | *Required* 46 | Type: `string` 47 | 48 | #### options.port 49 | 50 | Type: `number` 51 | Default: `21` 52 | 53 | #### options.user 54 | 55 | Type: `string` 56 | Default: `'anonymous'` 57 | 58 | #### options.pass 59 | 60 | Type: `string` 61 | Default: `'@anonymous'` 62 | 63 | #### options.remotePath 64 | 65 | Type: `string` 66 | Default: `'/'` 67 | 68 | The remote path to upload too. 69 | 70 | Nonexistent directories will be created for you. 71 | 72 | 73 | ## License 74 | 75 | MIT © [Sindre Sorhus](http://sindresorhus.com) 76 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var assert = require('assert'); 3 | var fs = require('fs'); 4 | var gutil = require('gulp-util'); 5 | var Server = require('ftp-test-server'); 6 | var pathExists = require('path-exists'); 7 | var ftp = require('./'); 8 | var mockServer; 9 | 10 | before(function (done) { 11 | mockServer = new Server(); 12 | 13 | mockServer.init({ 14 | user: 'test', 15 | pass: 'test' 16 | }); 17 | 18 | mockServer.on('stdout', process.stdout.write.bind(process.stdout)); 19 | mockServer.on('stderr', process.stderr.write.bind(process.stderr)); 20 | 21 | setTimeout(done, 500); 22 | }); 23 | 24 | after(function () { 25 | mockServer.stop(); 26 | }); 27 | 28 | it('should upload files to FTP-server', function (cb) { 29 | var stream = ftp({ 30 | host: 'localhost', 31 | port: 3334, 32 | user: 'test', 33 | pass: 'test' 34 | }); 35 | 36 | setTimeout(function () { 37 | assert(pathExists.sync('fixture/fixture.txt')); 38 | assert(pathExists.sync('fixture/fixture2.txt')); 39 | fs.unlinkSync('fixture/fixture.txt'); 40 | fs.unlinkSync('fixture/fixture2.txt'); 41 | fs.rmdirSync('fixture'); 42 | cb(); 43 | }, 500); 44 | 45 | stream.write(new gutil.File({ 46 | cwd: __dirname, 47 | base: __dirname, 48 | path: __dirname + '/fixture/fixture.txt', 49 | contents: new Buffer('unicorns') 50 | })); 51 | 52 | stream.write(new gutil.File({ 53 | cwd: __dirname, 54 | base: __dirname, 55 | path: __dirname + '/fixture/fixture2.txt', 56 | contents: new Buffer('unicorns') 57 | })); 58 | }); 59 | --------------------------------------------------------------------------------