Giter VIP home page Giter VIP logo

sftp-promises's People

Contributors

brokenbot avatar dependabot[bot] avatar puyb avatar sandaveaws avatar

Stargazers

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

Watchers

 avatar  avatar

sftp-promises's Issues

How to create a new file?

sftp.put(
  __filename,
  pathOfNotExistOnSFTPServer,
);

or

sftp.putBuffer(
  Buffer.from(''),
  path.join('/home/mulps/www/app/build', __filename),
);

result:

Error: No such file

If the file does not exist, I want to create it and write it in the file.

Unable to catch error when a file doesn't exist

Hi,

I'm trying a basic stat on an non existing file:

    const sftp = new SFTPClient(credentials);
    return sftp.stat(path)
    .catch((err) => {
      console.error('Oups', err);
    })
    .then((entry) => {
      var filename = entry.path.split('/').pop();
      return {
        size: entry.size,
        modified: entry.mtime,
        name: filename,
        isDir: entry.type === 'directory',
        mime: Mime.lookup(filename)
      }
    });

I've got an error trace:

{ Error: No such file
    at SFTPStream._transform (/home/jbrichardet/Documents/workspace/unifile/node_modules/ssh2-streams/lib/sftp.js:405:27)
    at SFTPStream.Transform._read (_stream_transform.js:167:10)
    at SFTPStream._read (/home/jbrichardet/Documents/workspace/unifile/node_modules/ssh2-streams/lib/sftp.js:181:15)
    at SFTPStream.Transform._write (_stream_transform.js:155:12)
    at doWrite (_stream_writable.js:334:12)
    at writeOrBuffer (_stream_writable.js:320:5)
    at SFTPStream.Writable.write (_stream_writable.js:247:11)
    at Channel.ondata (_stream_readable.js:555:20)
    at emitOne (events.js:96:13)
    at Channel.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Channel.Readable.push (_stream_readable.js:134:10)
    at SSH2Stream.<anonymous> (/home/jbrichardet/Documents/workspace/unifile/node_modules/ssh2/lib/Channel.js:166:15)
    at emitOne (events.js:96:13)
    at SSH2Stream.emit (events.js:188:7)
    at parsePacket (/home/jbrichardet/Documents/workspace/unifile/node_modules/ssh2-streams/lib/ssh.js:3439:10) code: 2, lang: '' }`

but I'm unable to catch it, read the code and return a informative message to the user. Is my .catch at the wrong place?

Thank you

getting wrong time while performing ls

Hi,
I am getting wrong modification time and access time as json value, even though the directory is created long back it is giving today date please help.

Thanks in advance

Regarding Read And WriteStream

Hi, brokenbot,
can u please help me for readStream I tried but it is not coming as the proper response can u please help me.

sftp.put retuns true but files not getting transferred.

Here is my code

var SFTPClient = require('sftp-promises');
var path = require('path');

var config = {host: 'xx.xx.xx.xx', username: 'user', password: 'user' };
var sftp = new SFTPClient(config);

var localPath = path.normalize('test.txt');
var remotePath = path.normalize('/home/sftpfiles');

sftp.put(localPath, remotePath).then(function(res) { console.log(res) });
sftp.ls('/home/sftpfiles').then(function(list) { console.log(list) });

i am getting result as true, but no files get transferred in remote path.
i am using windows 10 with node.0.12.x

Unforgiving about path formatting

Very nice, but a bit twitchy about the format of paths. The example shown that uses:

sftp.ls('~/').then(function(list) { console.log(list) })

doesn't work as shown on my Mint/Ubuntu box. Mine requires:

sftp.ls('.').then(function(list) { console.log(list) })

to get the expected result.

Probably OS and sftp server dependent. I am running the OpenSSH daemon.

Dave

How to hook into the upload status?

I'm uploading large files using a stream. How can I figure out the upload percentage? I don't see any methods (since this is a promise) that give me access to the stream and the amount of data being chunked at a time.

Stream pipe fails in Node 10.15.3 when piping file with data

We recently upgraded from an older version of node to Node 10, and ever since I've been experiencing an issue with a read stream from a remote server just not working when attempting to pipe from the SFTP read stream.

An example of our setup:

console.log('Creating the stream');
let streamPromise = new Promise((resolve, reject) => {
	sftp.createReadStream('/Mydata/download_report.csv').then(stream => {
		console.log('Read stream created! Creating the write stream');
		let writeStream = fs.createWriteStream('download_report.csv');
		console.log('Write stream created!');
		stream.on('error', (error) => {
			console.error('Error in read stream', error);
			return reject(error);
		});
		stream.on('data', (data) => {
			console.log('data in read stream', Buffer.from(data, 'base64').toString());
		});
		stream.on('end', () => {
			try {
                writeStream.end();
              } catch(err) {
                // Suppress warning, but still resolve
                return resolve('Done! Resolved from stream.on end in the error handler for writeStream.end()');
              }
		});
		writeStream.on('data', (data) => {
			console.log('data in write stream', Buffer.from(data, 'base64').toString());
		});
		writeStream.on('error', error => {
			console.error('Error in write stream', error);
			return reject(error);
		});
		writeStream.on('finish', () => {
			console.log('Finish called in writeStream.')
			return resolve('Done! Resolved from stream.on finish in writeStream.');
		});
		
		console.log('Piping the stream');
		stream.pipe(writeStream);
	}).catch(error => {
		console.error('Error creating read stream', error);
		return reject(error);
	});
});

streamPromise.then((results) => {
	console.log('Stream Promise resolved!');
	console.log(results);
}).catch(console.error);

In our old Node installation, this logs out fine:

Creating the stream
Read stream created! Creating the write stream
Write stream created!
Piping the stream
data in read stream
Col A,Col B,Col C,Col D
a,b,c,d
Finish called in writeStream.
Done! Resolved from stream.on finish in writeStream.

Checking the local FS shows the file with all the expected data.

But in Node 10, the log is just:

Creating the stream
Read stream created! Creating the write stream
Write stream created!
Piping the stream

Then... nothing else. It just stops, and the local file is empty.

File type not recognize since node 6.3.0

Hello there,

I've encounter a compatibility break by switching from Node 6.2.2 to Node 6.3.0 (or higher, also try 6.3.1, 6.4.0, 6.5.0). I'm doing a ls command and my program is not detecting the file type (at least for directories). Here is my code:

let ftpConnection = new SftpClient(config.dataSourceOptions.sftpOptions)

return ftpConnection.ls(config.dataSourceOptions.sftpOptions.directory)
    .then(function(result)
    {
        console.log(result)
    })

Result with Node 6.2.2:

{
    path: "path/to/directory",
    type: "directory",
    attrs: {
        // ...
    },
    entries: [
        // ...
    ]
}

Result with Node >= 6.3.0

{
    path: "path/to/directory",
    type: "other",
    attrs: {
        // ...
    }
}

The directory type is not detected anymore. This is embarassing because I can't iterate through the "entry" option.

Now, I don't know if this is a (non-wanted) regression from Node or if it comes from this lib using deprecated code...

Thanks for your help.

"No such file" error when lsing subdirectory which exists

Here's the situation:

I have an SFTP server which has a folder within it. (I'd rather not use our actual SFTP server and folder names, so let's call this folder 'Mydata', matching the capitalization used in our setup).

When I ls the root directory using "." and loop over all of the folders within it, I successfully get a result whose entries list includes an entry with filename of "Mydata". I can subsequently stat that data using stat("./Mydata") to show that it is indeed a folder.

However, when I try to directly ls("./Mydata"), it consistently fails with "No such file". Trying ls("/Mydata") and ls("Mydata") also fail.

I'm absolutely baffled. I know I've successfully lsd other subdirectories of other FTP servers before, so what could be the problem with this one?

Version 1.8.0 is not backwards compatible and should have been a major version

One of the changes to 1.8.0 was updating SSH2 from 0.8.2 to 1.4.0. That should have resulted in a major version number for sftp-promises, since ssh2 had a major version update and was no longer backward compatible. And in fact, it was not. Version 0.8.2 supports Node as far back as v5, but version 1.4 requires v10+.

putBuffer is resolving to soon

Hi,

I just saw that putBuffer() resolve before the connection is closed. Looking in the code I saw a resolve outside of the close callback (and, I think, unnecessary).

Removing it solved my issue but I don't know if it has an other purpose.

getBuffer of zero byte file throws error

stack:
ssh2-streams/lib/sftp.js:826
throw new Error('offset is out of bounds');
^

Error: offset is out of bounds
at SFTPStream.readData (/home/vagrant/Projects/sftp-rest/node_modules/koa-sftp/node_modules/sftp-promises/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:826:11)
at SFTPWrapper.read (/home/vagrant/Projects/sftp-rest/node_modules/koa-sftp/node_modules/sftp-promises/node_modules/ssh2/lib/SFTPWrapper.js:45:23)
at /home/vagrant/Projects/sftp-rest/node_modules/koa-sftp/node_modules/sftp-promises/index.js:211:16
at SFTPStream._transform (/home/vagrant/Projects/sftp-rest/node_modules/koa-sftp/node_modules/sftp-promises/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:470:15)
at SFTPStream.Transform._read (_stream_transform.js:167:10)
at SFTPStream._read (/home/vagrant/Projects/sftp-rest/node_modules/koa-sftp/node_modules/sftp-promises/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:173:15)
at SFTPStream.Transform._write (_stream_transform.js:155:12)
at doWrite (_stream_writable.js:292:12)
at writeOrBuffer (_stream_writable.js:278:5)
at SFTPStream.Writable.write (_stream_writable.js:207:11)

Need to check for this before attempting transfer.

Promise not getting rejected in case of invalid credentials.

Hi,

I am using the following code in order to verify the credentials.

    const config = {
        host: req.body.hostname,
        username: req.body.username,
        password: req.body.password,
        port: req.body.port
    };

    try {
        const sftp = new SFTPClient(config);
        const session = yield sftp.session(config); // get session
        session.end(); //end the session if exists
    } catch (error) {
        throw `Could not validate the credentials.`
    }

With wrong credentials, the function session() should reject the promise but it doesn't. It just gets struck forever.

I also have the following code:

    //handling all the uncaught exception
    process.on('uncaughtException', error => console.log(`Caught exception: ${error}` ));

The exception is caught at this level (twice):

Caught exception: Error: All configured authentication methods failed
Caught exception: Error: Timed out while waiting for handshake

Can you please look into the issue.

Version: 1.4.0
Node Version: v6.9.4
NPM Version: 3.10.10

Note: Don't get confuse by yield I am using co library to handle the promises.

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.