Hi Folks, Maybe someone knows how to so this!
Say I'm logged in to a remote host in a telnet session.
At a certain point, I would like to send the contents of a text file to the other end (as if I'd typed them in by hand).
OK, in principle I could do this by opening the file in another xterm, and using the mouse to paste the lines into my telnet session. But in this instance I don't want to do that.
What I'd really like to do is to be able to "break out" of the direct connection between my keyboard and the far end, and issue a local command to squirt said file down the line via the telnet session. And then break back in again.
There doesn't seem to be any method of doing this with normal telnet (as far as I can make out from 'man telnet').
Any suggestions?
(After all, one used to be able to do this kind of thing with kermit, when on dial-up via a serial port!)
With thanks, and best wishes to all, Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) ted.harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 08-Oct-07 Time: 18:09:37 ------------------------------ XFMail ------------------------------
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.
On 10/8/07, Ted Harding ted.harding@nessie.mcc.ac.uk wrote:
Say I'm logged in to a remote host in a telnet session. At a certain point, I would like to send the contents of a text file to the other end (as if I'd typed them in by hand).
...
What I'd really like to do is to be able to "break out" of the direct connection between my keyboard and the far end, and issue a local command to squirt said file down the line via the telnet session. And then break back in again.
Sending the Escape code (usually by pressing ^] ) should break out of the telnet session.
The next step of sending a text file, I'm not sure.
Can you run "screen"? That has copy and paste facilities for the mouseless.
Tim.
On 09-Oct-07 09:25:24, Tim Green wrote:
On 10/8/07, Ted Harding ted.harding@nessie.mcc.ac.uk wrote:
Say I'm logged in to a remote host in a telnet session. At a certain point, I would like to send the contents of a text file to the other end (as if I'd typed them in by hand).
...
What I'd really like to do is to be able to "break out" of the direct connection between my keyboard and the far end, and issue a local command to squirt said file down the line via the telnet session. And then break back in again.
Sending the Escape code (usually by pressing ^] ) should break out of the telnet session.
The next step of sending a text file, I'm not sure.
Thanks for the comment -- that's exactly where I found myself! I knew about ^], but couldn't find anyway to call up a file to squirt down the line once one has broken out.
Can you run "screen"? That has copy and paste facilities for the mouseless.
I'll have a look at it, though "copy and paste" is not what I'm after -- which is to do the equivalent of 'cat file'.
Thanks also to Wayne and Greg for suggestions. I take the point about ssh but that *definitely* wouldn't work in this case.
Perhaps I'd better confess. I'm sending regular emails to an address abroad, routinely via my ISP (Zen). From time to time, I run into a bunch of delivery failures (usually timeouts), and I often get the error messages several (up to 10) hours later. Since these are work-related, loss of time has consequences.
I've located the SMTP servers for the remote site, and have had success in using bare-hands 'telnet ... 25' SMTP dialogue.
This has also revealed that the response time before a 'telnet ... 25' connects, if at all, can be some minutes; I guess ZEN's mailservers get fed up with waiting, each time they re-try, and in the end just chuck it back to me.
Howeve, *I* can afford to be patient, since I'm nobody's ISP!
This works easily for short emails: Once I've said 'helo', where I 'maik from:', and whom I want to 'rctp to:', I can type in headers, then a blank line, then the message. Then ".", and it's accepted for delivery. Simple.
But this ain't so simple for sending attachments (say a 100-KB PDF file)!
I can do a mock-up of the entire message, including the MIME headers and separators, the body, and the base64-encoded attachment, by simply mailing it to myself locally. Since I store messages in MH mailboxes, each message is a separate text file.
So all I would need to do is copy that file, edit out unwanted headers and modify others, and then 'cat' the edited copy down the line after the 'data' command in SMTP.
Or that would be the case, if only I could find out how to 'cat it down the line' while still on that telnet connection!
(Perhaps one can see why ssh wouldn't work iin this case ... :))
Thanks, Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) ted.harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 09-Oct-07 Time: 14:08:00 ------------------------------ XFMail ------------------------------
On 10/9/07, Ted Harding ted.harding@nessie.mcc.ac.uk wrote:
I can do a mock-up of the entire message, including the MIME headers and separators, the body, and the base64-encoded attachment, by simply mailing it to myself locally. Since I store messages in MH mailboxes, each message is a separate text file.
So all I would need to do is copy that file, edit out unwanted headers and modify others, and then 'cat' the edited copy down the line after the 'data' command in SMTP.
Or that would be the case, if only I could find out how to 'cat it down the line' while still on that telnet connection!
This is sounding more like a job for netcat, also known as nc. Or an SMTP agent with a more patient connect timeout period.
Good luck! Tim.
On 09/10/2007, Tim Green timothy.j.green@gmail.com wrote:
On 10/9/07, Ted Harding ted.harding@nessie.mcc.ac.uk wrote:
I can do a mock-up of the entire message, including the MIME headers and separators, the body, and the base64-encoded attachment, by simply mailing it to myself locally. Since I store messages in MH mailboxes, each message is a separate text file.
So all I would need to do is copy that file, edit out unwanted headers and modify others, and then 'cat' the edited copy down the line after the 'data' command in SMTP.
Or that would be the case, if only I could find out how to 'cat it down the line' while still on that telnet connection!
This is sounding more like a job for netcat, also known as nc. Or an SMTP agent with a more patient connect timeout period.
This sounds like a job for expect. Expect a telent session, then send over the text file.
Srdjan
Srdjan Todorovic wrote:
This sounds like a job for expect. Expect a telent session, then send over the text file.
+1 on that: expect is a very useful tool that's often forgotten about (or not known about!). Indeed I haven't used it for ages and had forgotten its existence, so thanks for the reminder!
On 09-Oct-07 15:24:10, Srdjan Todorovic wrote:
On 09/10/2007, Tim Green timothy.j.green@gmail.com wrote:
On 10/9/07, Ted Harding ted.harding@nessie.mcc.ac.uk wrote:
I can do a mock-up of the entire message, including the MIME headers and separators, the body, and the base64-encoded attachment, by simply mailing it to myself locally. Since I store messages in MH mailboxes, each message is a separate text file.
So all I would need to do is copy that file, edit out unwanted headers and modify others, and then 'cat' the edited copy down the line after the 'data' command in SMTP.
Or that would be the case, if only I could find out how to 'cat it down the line' while still on that telnet connection!
This is sounding more like a job for netcat, also known as nc. Or an SMTP agent with a more patient connect timeout period.
That is not in my control!
This sounds like a job for expect. Expect a telent session, then send over the text file.
Srdjan
Now that could be promising! I knew (but had forgotten) about expect (It's what used to do my dial-up, in the back-office of kppp).
I'll have to study it, and experiment "locally" -- as I recall you have to be pretty careful to plan it right, or things can fall over badly.
The last thing I want to do is to poke sticks into wasps' nests at the remote site, by engaging in automated fumble-prone SMTP dialogues with their servers!
Best wishes, Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) ted.harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 09-Oct-07 Time: 17:13:22 ------------------------------ XFMail ------------------------------
On Tue, Oct 09, 2007 at 04:04:49PM +0100, Ted Harding wrote:
So all I would need to do is copy that file, edit out unwanted headers and modify others, and then 'cat' the edited copy down the line after the 'data' command in SMTP.
Or that would be the case, if only I could find out how to 'cat it down the line' while still on that telnet connection!
(Perhaps one can see why ssh wouldn't work iin this case ... :))
Why not open the socket in your favourite programming language and parse the responses etc... it should be relatively easy to knock up something that does this in either python or perl...
Heck, this being pure telnet, you might even be able to just use expect to do it...
Something like the attached script should give you an idea (OK - so there's a bug in the attached script... but hey ;)
Cheers,
On 09-Oct-07 15:48:25, Brett Parker wrote:
On Tue, Oct 09, 2007 at 04:04:49PM +0100, Ted Harding wrote:
So all I would need to do is copy that file, edit out unwanted headers and modify others, and then 'cat' the edited copy down the line after the 'data' command in SMTP.
Or that would be the case, if only I could find out how to 'cat it down the line' while still on that telnet connection!
(Perhaps one can see why ssh wouldn't work iin this case ... :))
Why not open the socket in your favourite programming language and parse the responses etc... it should be relatively easy to knock up something that does this in either python or perl...
Heck, this being pure telnet, you might even be able to just use expect to do it...
Something like the attached script should give you an idea (OK - so there's a bug in the attached script... but hey ;)
Looks neat! I'll give it a try -- though there's summat weird garbage in there that I'll have to clean out ... :)
Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) ted.harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 09-Oct-07 Time: 20:24:30 ------------------------------ XFMail ------------------------------
Ted,
On 9 Oct 2007, at 4:04 pm, (Ted Harding) wrote:
Perhaps I'd better confess. I'm sending regular emails to an address abroad, routinely via my ISP (Zen). From time to time, I run into a bunch of delivery failures (usually timeouts), and I often get the error messages several (up to 10) hours later. Since these are work-related, loss of time has consequences.
I've located the SMTP servers for the remote site, and have had success in using bare-hands 'telnet ... 25' SMTP dialogue.
You could just set up the mailserver that you're telneting to as another outgoing mailserver in your mail client and send the email like that. Obviously this would only work for the one company you're trying to email.
Thanks,
David
On 09-Oct-07 15:52:27, David Reynolds wrote:
Ted,
On 9 Oct 2007, at 4:04 pm, (Ted Harding) wrote:
Perhaps I'd better confess. I'm sending regular emails to an address abroad, routinely via my ISP (Zen). From time to time, I run into a bunch of delivery failures (usually timeouts), and I often get the error messages several (up to 10) hours later. Since these are work-related, loss of time has consequences.
I've located the SMTP servers for the remote site, and have had success in using bare-hands 'telnet ... 25' SMTP dialogue.
You could just set up the mailserver that you're telneting to as another outgoing mailserver in your mail client and send the email like that. Obviously this would only work for the one company you're trying to email.
In theory, yes. In practice, it would probably get too complicated. I've identified about 8 different hosts that act as mailservers there, and they tend to be somewhat randomly available.
Even the blanket "mail.***.***.***" doesn't always respond (though then another one might), and when it does is either "itself" or appears to be aliased to one of the others (I've seen the IP change from what 'telnet' announces it's connecting to, and what the server gives as its IP when it signs off).
Also, I'd have to run a differently configured instance of my mail client (XFMail) since I can choose one but only one of sendmail, SMTP or POP as "send" method. I'm normally on "sendmail in background" (i.e. outgoing mail gets batched in an outbox until I give the go-ahead), and I'd need to switch to SMTP; I'd also have to change the SMTP host configuration. In practice this would all mean shutting down my normal instance and starting one with a different config file; and then I'd still potentially be stymied by the multi-server situation described above.
My strategy so far is to "round-robin" my list until I get a definite response, and carry on from there. This looks like something that expect should be able to handle, provided I can anticipate the different responses that could occur in different situations (including recalcitrant remote server following apparently successful connection)..
Thanks, Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 09-Oct-07 Time: 17:39:41 ------------------------------ XFMail ------------------------------
-------------------------------------------------------------------- E-Mail: (Ted Harding) ted.harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 09-Oct-07 Time: 18:33:25 ------------------------------ XFMail ------------------------------