Closed 7vs closed 10 years ago
Hi, What grunt plugin are you talking about? I never use grunt but I think I can easily understand how it works. Thank you
Thanks for answering, I've change to use your solution, but I need to wrap it in a task, but it's giving me this error:
var FTPS = require('ftps');
^^^^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected identifier
Warning: Task "watch" not found. Use --force to continue.
Aborted due to warnings.
This is my code:
module.exports = function(grunt) {
grunt.initConfig({
ftpaccess: grunt.file.readJSON('ftpaccess.json'),
// running `grunt less` will compile once
less: {
development: {
options: {
paths: ["css"],
sourcemap: "sourcemap/style.css.map"
},
files: {
"css/styles.css": "less/styles.less"
}
},
production: {
options: {
paths: ["css"],
cleancss: true
},
files: {
"css/style.min.css": "less/styles.less"
}
}
},
ftpupload: {
build: {
var FTPS = require('ftps');
var ftps = new FTPS({
host: '<%= ftpaccess.host1 %>', // required
username: '<%= ftpaccess.key1.username %>', // required
password: '<%= ftpaccess.key1.password %>', // required
protocol: 'ftps', // optional, values : 'ftp', 'sftp', 'ftps',... default is 'ftp'
// protocol is added on beginning of host, ex : sftp://domain.com in this case
port: 21 // optional
// port is added to the end of the host, ex: sftp://domain.com:22 in this case
});
// Do some amazing things
ftps.cd('/wwwroot/xxx-practice-installation/xxx-practice-installation/base-install/css').addFile('css/styles.css').exec(console.log);
}
},
// running `grunt watch` will watch for changes
watch: {
files: "less/**/*.less",
tasks: ["less:development", "ftpupload"]
}
});
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
};
Hi!
I look into your code, and I changed it to work correctly. Here the new code:
module.exports = function(grunt) {
grunt.initConfig({
ftpaccess: grunt.file.readJSON('ftpaccess.json'),
// running `grunt less` will compile once
less: {
development: {
options: {
paths: ["css"],
sourcemap: "sourcemap/style.css.map"
},
files: {
"css/styles.css": "less/styles.less"
}
},
production: {
options: {
paths: ["css"],
cleancss: true
},
files: {
"css/style.min.css": "less/styles.less"
}
}
},
// running `grunt watch` will watch for changes
watch: {
files: "less/**/*.less",
tasks: ["less:development", "ftpupload"]
}
});
grunt.registerTask('ftpupload', function () {
// render this task asynchronous
var done = this.async();
var FTPS = require('ftps');
var ftps = new FTPS({
host: grunt.template.process('<%= ftpaccess.host1 %>'), // required
username: grunt.template.process('<%= ftpaccess.key1.username %>'), // required
password: grunt.template.process('<%= ftpaccess.key1.password %>'), // required
protocol: 'ftps', // optional, values : 'ftp', 'sftp', 'ftps',... default is 'ftp'
// protocol is added on beginning of host, ex : sftp://domain.com in this case
// port: 22 // optional
// port is added to the end of the host, ex: sftp://domain.com:22 in this case
});
// Do some amazing things
ftps
.cd('/wwwroot/xxx-practice-installation/xxx-practice-installation/base-install/css')
.addFile('css/styles.css')
.exec(function (err, res) {
if (res.error)
return grunt.log.error(res.error);
grunt.log.writeln('Upload done!');
done();
});
});
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
};
As you can see, I register a custom task with the grunt.resgisterTask
method.
You can call grunt watch
and update your .less file, it works perfectly for me :)
Thank you very much Aaron, for this, really! The implemented code seems to work. It doesn't gives any errors, but when I look at the file in the server is not updated. I'm trying to find out what could be the issue, because when I change the port it shows me a conexion error, i.e.: port 22, or port 993, so I'm figuring out that might be the transfer / location of the file and not the connection. And I also tried it with another grunt plugin with the same results... Any suggestion to test would be really appreciated! rgds.
Hi Atinux,
I'm really interesting in implementing your solution and I'm almost there. 1.- How can I debug it to see what is not working?
$ grunt watch Running "watch" task Waiting...
File "less/custom/home-page.less" changed. Running "less:development" (less) task File ./css/styles.css created: 0 B → 96.4 kB
Running "ftpupload" task Upload done!
Done, without errors. Completed in 3.808s at Mon Sep 15 2014 09:56:00 GMT+0100 (BST) - Waiting...
It seems that the file is uploaded but when I check it in my ftp client it's not updated whatsoever...? 2.- What am I doing wrong?
So far, I think yours is the only solution I can use in order to transfer files to an FTP server with SSL layer. Here is my configuration:
My environment: Mac OS maverick,
FTP server: FTP-SSL (Explicit AUTH TLS), port 21... Connect mode: passive (PASV)
You also said in the requirements section in your read me file that: 'You need to have the executable lftp installed on your computer.'
3.- How can I know if I have it already installed, and otherwise, how can I do to install it properly? Could be this the issue?
Thanks, rgds.
Hi 7vs,
1 - You can try to debug by checking res.data
:
ftps
.cd('/wwwroot/xxx-practice-installation/xxx-practice-installation/base-install/css')
.addFile('css/styles.css')
.exec(function (err, res) {
if (res.error)
return grunt.log.error(res.error);
console.log(res.data);
grunt.log.writeln('Upload done!');
done();
});
2 - I have no idea what you're doing wrong, because it works for me, maybe it's because you don't have the rights for adding a file in the destination folder?
3 - Open your terminal, and launch this command lftp --version
, if you don't have any error, lftp is installed correctly on your computer!
Ok, thanks, I have not installed lftp. is it a node module?
$ lftp --version -bash: lftp: command not found
By the way, I've found this... https://www.npmjs.org/package/grunt-ftps What do you think? rgds
You need to install lftp with Homebrew (or others command to install stuff on macs): brew install lftp
For installing Homebrew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Website: http://brew.sh/
For the module grunt-ftps, this guy is using my code (node-ftps), so it's exactly the same solution by published on grunt (as I can see).
Yes, I already find the way to install lftp, thanks!
Haha, I was supposing that it was your code...
oK now we are progressing, I've installed the lftp and I've included the 'console.log(res.data);' line and I have this error in the terminal:
Running "ftpupload" task
cd: Fatal error: SSL_connect: unknown protocol put: ./css/styles.css: Fatal error: SSL_connect: unknown protocol
I think is the type of protocol specified in your code because I changed it to simple ftp and it gives me this error:
cd: Login failed: 534 Policy requires SSL. put: ./css/styles.css: Login failed: 534 Policy requires SSL.
Have you tried protocol: 'sftp'
?
Thank you Atinux, Yes I've tried that with another plugin (and now with yours) but my protocol is 'ftps' and not 'sftp'. I don't know what could be happening... :( I'll still try to solve it.
@7vs did you ever get anywhere with this?
@jwhitmarsh, No I didn't, why?
Hi Atinux, I come from the issue described in this link. https://github.com/sergi/jsftp/issues/39 I'm trying to use this grunt plugin, but I need to add the SSL layer as the protocol needed to transfer to my ftp server is ftps. How can I implement your solution in this plugin customised by myself? thanks rgds