GithubHelp home page GithubHelp logo

grunt-ftp's Introduction

grunt-ftp

Upload files to or download from an FTP-server

Useful for uploading, deploying and downloading things.

Install

$ npm install --save-dev grunt-ftp

Usage

Upload

require('load-grunt-tasks')(grunt); // npm install --save-dev load-grunt-tasks

grunt.initConfig({
	ftpPut: {
		options: {
			host: 'website.com',
			user: 'johndoe',
			pass: '1234'
		},
		upload: {
			files: {
				'public_html': 'src/*'
			}
		}
	}
});

grunt.registerTask('default', ['ftpPut']);

Download

require('load-grunt-tasks')(grunt); // npm install --save-dev load-grunt-tasks

grunt.initConfig({
	ftpGet: {
		options: {
			host: 'website.com',
			user: 'johndoe',
			pass: '1234'
		},
		download: {
			files: {
				'public_html/file.txt': 'src/file.txt'
			}
		}
	}
});

grunt.registerTask('default', ['ftpGet']);

Options

host

Required
Type: string

port

Type: number
Default: 21

user

Type: string
Default: 'anonymous'

pass

Type: string
Default: '@anonymous'

grunt-ftp's People

Contributors

sindresorhus avatar vincent-boulin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-ftp's Issues

Never uploads more than one file

I'm not sure what's wrong with my config:

  upload: {
    files: {
      '': 'dist/*'
    }
  }

It basically uploads the first file in the dist folder to the server. How to have all files included? Also how to include subfolders and their content recursively?

on windows systems using path.join for the remote path causes hilarity

Hi There,

I'm running on windows.

After I ftpPut a file I see:

  • a file in the root directory on the ftp server named "\img\buddies1.png"
  • directory named "img"
  • nothing in the "img" directory

I believe the behavior is due to finalRemotePath:
var finalRemotePath = path.join('/', el.dest, el.src[0]);

Which is being used when calling ftp.put:
ftp.put(buffer, finalRemotePath, function (err) {

I'm not 100% confident but AFAIK windows ftp servers support forward slash.

I'm pretty sure a function like the below would work:
var posixPath = function(filepath) { if (path.sep !== '/') { return filepath.split(path.sep).join('/'); } else { return filePath; } };

I'll fork and submit a PR if you're in agreement.

Thanks,

Matt

Here's my Gruntfile FWIW:

`module.exports = function (grunt) {

grunt.initConfig({
    ftpPut: {
        options: {
            host: 'ftp.site.com',
            user: 'admin',
            pass: '1234'
        },
        upload: {
            files: [
                {src: 'img/buddies1.png', dest: ''},
            ]
        }
    }
});

grunt.loadNpmTasks('grunt-ftp');

grunt.registerTask('default', ['ftpPut']);

}`

Only one file uploading

With this config:

ftp: {
    options: {
        host: 'ftp.example.com',
        user: 'username',
        pass: process.env.PW,
        flatten: true
    },
    css: {
        files: {
            'public/css/' : 'source/css/*.css'
        }
    }
}

...with three css files in /source/css/ locally, I expected to see:
public/css/file1
public/css/file2
public/css/file3

But instead got:
public/css/source/css/file1

I am not totally sure if the path bit is a bug or a misconfiguration, but I've tried lots of options (file patterns, trying to pass the usual options to file, etc) to no avail. Passing the flatten option was a bit of a shot in the dark and appears to do nothing (tried it in the css object as well, also no effect).

Anyway, running grunt with --verbose shows three files detected but only one uploaded:

Running "ftp:css" (ftp) task
Verifying property ftp.css exists in config...OK
Files: source/css/file1.css, source/css/file2.css, source/css/file3.css -> public/css
Options: host="string", user="string", pass="string", flatten
Reading source/css/file1.css...OK
1 file uploaded successfully
Done, without errors.

Tried these variations:

'public/css/' : 'source/css/*.css' // result as described
'public/css/' : 'source/css/*.*' // result as described
'public/css' : 'source/css/**/*.css' // result as described
'public/css/' : 'source/css/' // results in Fatal error: Unable to read "source/css/" file (Error code: EISDIR).
'public' : 'source/css/*.css' // only one file uploaded, to public/source/css

I tried a few different sets of test files and it's always the first file (by filename) that gets uploaded.

Versions:
node v0.10.22
grunt v0.4.5
grunt-ftp v1.0.1
Run from OSX Terminal

Anyway... hopefully it's not just a misconfiguration that I didn't catch, but I'm a bit stumped regardless ;)

Configuration syntax

Hi,

I like your plugin. It is very usefull. But the configuration syntax isn't really standards compliant.

upload: {  // Target
            files: {   // Dictionary of files
                'public_html': 'src/*' // remote destination : source
            }
}

could be better with this syntax

upload: {  // Target
            files: {  // Dictionary of files
                src: 'src/*'  // source
                dest: 'public_html'  // remote destination
            }
}

What do you think about that ?

Thanks

Download Issue

I'm having some trouble downloading from a server. Here's my configuration:

ftpGet: {
    options: {
        host: '*****',
        user: '*****',
        pass: '*****'
    },
    download: {
        files: {
            'public_html/staging/': 'c:/users/mike/google drive/sourcetree/datacede.com/download-folder'
        }
    }
},

I have tried every possible variation of specifying the src for files (escaping, double back slashes, forward slashes, etc.) but each time I get the error:

Running "ftpGet:download" (ftpGet) task
Verifying property ftpGet.download exists in config...OK
Files: c:/users/mike/google drive/sourcetree/datacede.com/download-folder -> public_html/staging/
Options: host="*****", user="*****", pass="*****"
Warning: 550 Can't open c:/users/mike/google drive/sourcetree/datacede.com/download-folder: No such file or directory Use --force to continue.

I've also made certain that this folder exists and is writable on my OS. What am I doing wrong? I really appreciate the help as this plugin when working will make site deployments super easy. Cheers.

there is question about downLoad?

look,this picture is in grunt
qq 20151104195440_
when i excute grunt fileGet
there is error
image
I use the console.log output information in command-line and i know grunt-ftp how to work~
I found that the paramter of ftp.get() function el.src[0] not exist.so I double right or false,bug?
I don‘t no what a reason
I am chinese.
PS:FTP:I use local ftp server,OS:win8.1
regards!

Escaping Username

I am having an issue logging into my company ftp server.

The problem is with the username. Because there is a domain associated with the account, I need to use a backslash. However, the first letter of the username is an 'n' due to company naming policy.

Somewhere along the line, \n is being replaced with \r\n, and the login fails.

Any attempts to escape the backslash fail as well. For instance using \n results in \n.

examples:
domain\njones becomes domain\r\njones
domain\njones stays the same
domain\njones becomes domain\r\njones

This is what I'm using for the options object.
{
"host": "111.111.111.111",
"port": 2222,
"username": "domain\njones",
"password": "supersecretpassword"
}

Is this a bug?
If not, what can I do so that it will accept the username properly?

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.