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

streaming & sequential commands #53

Open
jeromew opened this issue Jun 9, 2017 · 1 comment
Open

streaming & sequential commands #53

jeromew opened this issue Jun 9, 2017 · 1 comment

Comments

@jeromew
Copy link
Contributor

jeromew commented Jun 9, 2017

Hello,

I have been working happily with ftps using the execAsStream feature, piping data out of the stream.

Now I ran into a use case where I want execute many commands, and I can't really bundle all the commands into the command array because there are too many.

I started by invoking execAsStream for each command but this seems to be a deadend because of the overhead of the connection (I need to connect to the ftp server for each command which takes time)

Now I realized that execAsStream also works if instead of the lftp -c option, we use lftp -e.
This way, it is possible to write things like

var ftps = new lftp(config)
var stream = ftps.raw('cd /myRep').execAsStream()
stream.pipe(process.stdout)
stream.write('ls;\n');
stream.write('cd myRep2;\n');
setTimeout(function() {}, 1000) {
  stream.write('ls;\n');
  stream.write('exit;\n');
}

or pipe any stream of command into lftp.

This is a huge boost because this way we can maintain the lftp session (no need for reconnection) and write sequences of commands to it.

I don't think there are many users of the execAsStream feature so I propose to make the change and change the documentation accordingly (this would require a major version change because users would need to call stream.write('exit;\n'); to end the lftp session)

Another option would be to have a new method, execAsDuplex which would make it clear that

  • execAsStream is a Readable
  • execAsDuplex is a Duplex stream

What do you think ?

@jeromew
Copy link
Contributor Author

jeromew commented Jun 28, 2017

@atinux sorry to bother you again on this.

For a more easily acceptable PR, I can propose you to simply add an option for the type of launch.

autoExit: true/false (default true)

when set to true, this option would use "lftp -c" and when used with false, it would use "lftp -e".

Do you think you could accept this and publish a new version after my PR ?

Thanks for your time.

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

1 participant