Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFTP client fastPut error #265

Closed
sambengtson opened this issue May 6, 2015 · 2 comments
Closed

SFTP client fastPut error #265

sambengtson opened this issue May 6, 2015 · 2 comments

Comments

@sambengtson
Copy link

I can successfully connect to the server and get a directory listing, but when attempting to upload a file, I get a failure with the following stack trace with the following code:

ftp.on('ready', function () {

    console.log('connection success');
    ftp.sftp(function (err, sftp) {
        if (err)
            throw err;

        sftp.fastPut(currentFile, '/', function (err) {
            if (err) throw err;
            console.log('done');
        });
    });
});

Error: Failure
at SFTPStream._transform (C:\Users\sam.bengtson\Documents\NodeProjects\nodejs\tsm-usg-batch\node_modules\ssh2\node_modules\ssh2-streams\lib\sftp.js:354:27)
at SFTPStream.Transform._read as __read
at SFTPStream._read (C:\Users\sam.bengtson\Documents\NodeProjects\nodejs\tsm-usg-batch\node_modules\ssh2\node_modules\ssh2-streams\lib\sftp.js:160:15)
at SFTPStream.Transform._write (_stream_transform.js:167:12)
at doWrite (_stream_writable.js:301:12)
at writeOrBuffer (_stream_writable.js:288:5)
at SFTPStream.Writable.write (_stream_writable.js:217:11)
at Channel.ondata (_stream_readable.js:540:20)
at Channel.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)

Any thoughts?

@mscdex
Copy link
Owner

mscdex commented May 6, 2015

You're missing the filename in the destination path. Try something like this:

var basename = require('path').basename;
// ...
ftp.on('ready', function () {
    console.log('connection success');
    ftp.sftp(function (err, sftp) {
        if (err)
            throw err;

        sftp.fastPut(currentFile, '/' + basename(currentFile), function (err) {
            if (err) throw err;
            console.log('done');
        });
    });
});

I should also point out that this will try to write to the root of the filesystem on the server, which your user may not have access to, so you may still get an error (due to insufficient permissions). If you want to save to the user's home directory or relative to the home directory, you can simply use the filename for the destination or use a relative path specifier (e.g. './foo/' + basename(currentFile) to upload to /home/user/foo/) since OpenSSH (and probably other servers) start with the cwd set to the user's home directory. Otherwise if you're wanting to upload anywhere else, you'll need to use the absolute path.

@mscdex mscdex closed this as completed May 6, 2015
@sovanna
Copy link

sovanna commented Jul 2, 2015

thx it helps me.. haha, didn't know that for remotePath, we have to put the name of the file..
thank again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants