Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I urgently require a tip which will 1

Status
Not open for further replies.

dilse

Programmer
Jul 21, 2001
6
0
0
IN
I urgently require a tip which will execute some simple unix commands (eg. "ls" or "cd" etc. )in a remote unix server where i have permissions (user id and passwd) .I am using the following code....

import sun.net.*;
import sun.net.ftp.*;
import java.io.*;
class myftp1
{
public static void main(String args[])
{
String site = "address of machine here";
String login = "abc";// **ENTER YOUR OWN Login
String password = "abc";// **ENTER YOUR PASSWORD
String fileToGet = "files.txt";
FtpClient fc;
TelnetInputStream tis;
TelnetOutputStream tos;
FileInputStream fis;
FileOutputStream fos;
try
{
fc = new FtpClient(site);/* connect to site */
/* print the site's response */
System.out.println(fc.getResponseString());

/* send login and password */
fc.login(login,password);
/* print the site's response */
System.out.println(fc.getResponseString());
tis = fc.get(fileToGet);


i want to execute the command from here .

Can anyone help..

Regards

 
can u help a little by tell me that library u are using for the FTPClient??? if you look in the documentation i'm sure u will find an execte(), remoteExecute() or some command like that that will allow you to execute remote commands
 
thats SO much help :(

where did u get them?? whats the name of the jar files? do u have documentation for them????
 
The ftpclient class you are using allows you to change directory via:

fc.cd(<dir name as string>);

To get a file listing is a bit more work. The Ftpclient class gives you a telnetinputstream as the return value when you call:

fc.list();

You need to use that InputStream to get the file listing via:

TelnetInputStream tis = fc.list();
char c;
while ((c = (char)tis.read()) != -1)
System.out.print(c);

This is ugly but it is all the class gives you. You cannot use this class to execute OTHER system commands on the remote system. The only methods that do this are protected.

If you want to use this to get a list of filenames, you are going to have to do ALOT of work to convert the character output of the stream to a string and then parse the resulting directory listing string to extract filenames. This class was written for internal use via the HotJava browser so it doesn't have alot of functionality.

Regards,

Charles
meadandale@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top