streaming & sequential commands
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 ?
@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.