I am trying to use lrzsz to send a file by zmodem by reading stdio in java and forwarding it to a socket of a connected client.
private void sendFiles(ArrayList<String> filenames) {
Process p;
ProcessBuilder pb;
filenames.add(0, "/opt/local/bin/sz");
try {
pb = new ProcessBuilder(filenames);
p = pb.start();
InputStreamReader lrzszin = new InputStreamReader(p.getInputStream());
OutputStreamWriter lrzszout = new OutputStreamWriter(p.getOutputStream());
InputStreamReader telnetin = new InputStreamReader(socket.getInputStream());
OutputStreamWriter telnetout = new OutputStreamWriter(socket.getOutputStream());
while (p.isAlive()) {
if (lrzszin.ready()) {
telnetout.write(lrzszin.read());
telnetout.flush();
}
if (telnetin.ready()) {
lrzszout.write(telnetin.read());
lrzszout.flush();
}
}
} catch (IOException ex) {
}
}
However the zmodem downloads are coming through corrupted. and it errors out.
Answering my own question...
I needed to add the correct character encodings to the input and output streams.
While SEXYZ telnet option accounts for the IAC characters, I am not sure if lrzsz does (probably not) so I added Brian's suggestion of escaping them as well.