mscdex / node-ftp

An FTP client module for node.js
MIT License
1.13k stars 243 forks source link

Folder With Spaces #131

Open ghost opened 9 years ago

ghost commented 9 years ago

Hi. When a try upload something like that

./uploads/cool_image.jpg in /SERVER/Demo/Cool Folder/Hydrangeas.jpg

The application give the next error:

Error: /SERVER/Demo/Cool Folder/Hydrangeas.jpg: Permission denied. at makeError (PATH\node_modules\ftp\lib\connection.js:1067:13) at Parser. (PATH\node_modules\ftp\lib\connection.js:113:25) at Parser.emit (events.js:110:17) at Parser._write (PATH\node_modules\ftp\lib\parser.js:59:10) at doWrite (_stream_writable.js:301:12) at writeOrBuffer (_stream_writable.js:288:5) at Parser.Writable.write (_stream_writable.js:217:11) at Socket.ondata (PATH\node_modules\ftp\lib\connection.js:273:20) at Socket.emit (events.js:107:17) at readableAddChunk (_stream_readable.js:163:16) at Socket.Readable.push (_stream_readable.js:126:10) at TCP.onread (net.js:538:20) error: Forever detected script exited with code: 1 error: Script restart attempt #2

I think is for the space in folder name, but in the documentation i Couldn't find how to solve it.

Is this a Bug?

scagood commented 9 years ago

I know this is veeery late but I got stuck on this for far too long so I figured I'd reply here to try to help others:

The solution is remarkably simple, make it recursive so that node-ftp navigates to the path to run the 'MKD' command

mkdir(< string >path, [< boolean >recursive, ]< function >callback) - (void) - Creates a new directory, path, on the server. recursive is for enabling a 'mkdir -p' algorithm and defaults to false. callback has 1 parameter: < Error >err. (From Readme)

example:

var Client = require('ftp');

var ftpDetails = {};
var ftpCon = new Client(),

function ftpErr(err) {
    if (err) {
        console.log(err);
        ftpCon.end();
    }
}

ftpCon.on('ready', function() {
    var path = "/path/you want/with spaces";
    console.log("addDir:", path)
    // ftpCon.mkdir(path, ftpErr); // this is non recursive
    // ftpCon.mkdir(path, false, ftpErr); // as is this
    ftpCon.mkdir(path, true, ftpErr);
    ftpCon.end();
});
ftpCon.connect(ftpDetails);

Command structure for recursive:

addDir: /path/you want/with spaces // console.log
PWD
CWD /
CWD path
CWD you want
CWD with spaces
MKD with spaces

Command structure for non recursive:

addDir: /path/you want/with spaces // console.log
MKD /twitch/alerts/New folder

If you want to know why this works I cannot help you but it works :stuck_out_tongue:

Hope this helps scagood

igabesz commented 8 years ago

Try backslashing the spaces in the folder name, as I mention it in the referenced issue.