Wednesday, January 6, 2010

Java Ftp Api How To "TELNET / FTP" Through Java Using Runtime.exec() Cmd.?

How to "TELNET / FTP" through java using Runtime.exec() cmd.? - java ftp api

I know there are various APIs available to do this, but I want to know if there is an embodiment of telnet / ftp with Runtime.exec () command in Java. Because what I do not work
I have the process as follows:
Runtime rt = Runtime.getRuntime ();
Process p = rt.exec ( "telnet 12.42.28.123 25");

I have the input stream of this process:
InputStreamReader isr1 = new InputStreamReader
(p.getInputStream ());

I get the error stream of this process:
InputStreamReader isr2 = new InputStreamReader
(p.getErrorStream ());

I have the migration of this process:
PrintWriter pw = new PrintWriter
(P.getOutputStream ());

You should be able to read, the input sequence and the sequence of errors in this process. Ishould information, the ability to type commands on the issuance of this process, but no i / p, err stream, or E / P workflow and function p.waitFor () always returns -1. I'm using Windows XP operating system with Java version

2 comments:

McFate said...

Telnet (at least on Unix, where I am most familiar with it) is not really effective in a sub-process, and do not use the stdin / stdout - opens a direct connection to the terminal I / O.

Suppose you borrowed the Microsoft implementation of Unix, I do not take them to behave like the version of Windows possible. I acknowledge that I work with FTP rt.exec (), and well. Telnet is simply not well behaved.

Satya said...

Have you tried running the command in the menu?
What do you see? You see a window that you expect to type commands? If not, how woould expect java to do that? Java is here only on the surface offer and how do they work. Probably should first check whether the IP address is valid and able to connect to a normal routine.
If you is not that, what does not work the commands for you.
Mehtod p.waitFor is a block and wait for the return process with an exit code. Would you do it? Since you say you want the command of the reading again, I then wrote the code that is wrong.

First get the input stream and after, if you do not have success in connecttion server. If so, then I spend more jobs by clicking on the flow. Error stream, and entries will do the same here and the results in both .. no need to open, here 2-flows.
WAITFOR Since I am waiting for the purchase process. In the present case, such as Telnet or FTP is not working, you will always bean exit code -1 always. get an exit code of 0 in the process if the normal termination.

try again now with this, I believe that knowledge can do a better job.

Good luck,

Post a Comment