[ALUG] Inserting a file into a telnet session

Wayne Stallwood ALUGlist at digimatic.co.uk
Mon Oct 8 19:56:40 BST 2007


I don't know of a method to do explicitly what you want. Really you
should be using SSH as not only do you get the encryption as a layer of
security and key based logins but you also get niceties such as file
transfer and more relevant in your case I suspect, remote command
execution. One or both of which may solve your problem.

It would be possible to use netcat to inject commands piped in from a
file to a telnet server as if they had been typed in. But you would have
to manage the whole session that way (including login) which could get
more than a little bit icky. I can't see an easy way of jumping between
netcat and an interactive client for the same session. You could do
something nasty like telnet in, put whatever you were doing in screen
and get to the point where you want to inject commands. Then start a new
session alongside with nc being fed a script that logs in the session,
attaches the screen session with -x and issues the "typed" text. But I
think at that point you need to re-evaluate what you are doing and think
of a cleaner way. If not only because you are going to have to manage
line breaks etc the hard way but because it would probably fail horribly
as you can't manage pauses between login and shell etc.

Joking aside...I'd look into a way of doing what you want with ssh,
perhaps copying a file up and then remotely executing a command with the
file piped into it.






More information about the main mailing list