I’m writing a program where I need to telnet into a remote machine, access a file and edit it.
I am able to do the telnet part.
This gives me access to the OutputStream and InputStream of that system. I can send commands and open up the file using a vi editor. I am also able to read the contents of the file
DataInputStream data = new DataInputStream(telnet.getInputStream());
data.readLine().
But I am unable to write to this file or edit it.
Any suggestions?
I suspect that you are running into line-editing issues on the remote system. I think that using
sed(as @Jim Garrison mentioned) or using theededitor which is line based would work instead of the key based editor like vi or emacs.Here’s a quick example of how to use ed to edit the file named “file”.
man edshould show the various features.