Link to home
Start Free TrialLog in
Avatar of kedlu
kedlu

asked on

Delete files on remote machines AIX/LINUX/SOLARIS/WINDOWS with java.

Hello Everybody,

I want to write a program which will enable me to delete files from remote machines like AIX/LINUX/SOLARIS/WINDOWS. Is there any way I can do this task with java? I can't think of anything. Please suggest me.

Thanks,
Kedlu
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

That is primarily dependent on the network configuration of both machines. If you have the mechanisms in place you can just create a File and delete it

File f = new File("remotemachine:/a/b/c/d.txt");
boolean deleted = f.delete();
Avatar of kedlu
kedlu

ASKER

What do you mean by network configuration? I've AIX machine called "congo"
Linux machine called "zebra". So I just need to give following:

File f = new File("congo:/opt.testdir/test.txt");
boolean deleted = f.delete();

How will it contact remote machine? Doesn't it require username/password? I'm working on Windows 2000.

Thanks,
Kedlu
That's 3 OSs you've named. Are we talking about the same LAN?
There is one rule of thumb: if you can SEE a remote file in the local file manager, you can SEE it
with JAVA:    File f = new File("...............");  // Fill in the path.
If you have privileges you can delete the file from the file manager; then you can from JAVA.

;JOOP!
Avatar of kedlu

ASKER

All the three machines are on company's LAN, I can ping it, I can access it with telnet/ftp.
What is local file manager? I can't map to AIX or LINUX machines. If I have to manage files, i need to telnet to the machine and do file management.

I still did not understand how can I access it.
Thanks,
kedlu
You said you were on a Windows box. Can you do

dir \\congo\opt.testdir\test.txt

?
Avatar of kedlu

ASKER

No I can't. I get following erro:

The network path was not found.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If the only way to access those systems is by FTP, then you can use an FTP session
from JAVA to delete files, but it's clumsy.
;JOOP!
Avatar of kedlu

ASKER

I'm sorry, I was not in the city for few days.
CEHJ and JOOP, I did not understand how can I delete remote files with FTP session.
Can you provide me with sample program?

Thanks
You tell us which client you're using. You'll probably find there are examples in the download
Avatar of kedlu

ASKER

I'm using FTP which is installed on windows 2000. I did not install that. I guess it came with Windows 2000.
I'm talking about a *Java* client
Avatar of kedlu

ASKER

Oops...ok... java 1.3.1
So - you need to decide on a Java client. The sdk doesn't really support ftp
Avatar of kedlu

ASKER

So which java client will support ftp?
I posted a link earlier
Avatar of kedlu

ASKER

Let me try one of them. I will be back after trying...thanks!!
Avatar of kedlu

ASKER

Hello ,

I'm using FTPClient of Jakarta : commons-net-1.2.2.
Following is the sample code. To delete folder, I need to first list them and delete them one by one.
In following program I am just trying to list the files first. I get list of files of the current directory when user logs in and
changedirectory does not work. Can you please suggest me what is going wrong?

import org.apache.commons.net.ftp.*;
import org.apache.oro.text.regex.*;
/public static void main( String [] args) {
      
  try {
      
      FTPClient f= new FTPClient();
      f.connect("completemachinename");
      f.login("username","password");
      System.out.print(f.getReplyString());

      f.changeWorkingDirectory( "//opt//test" );
      FTPFile[] files = f.listFiles();
     
      for ( int i=0;i<files.length;i++)
      {
            System.out.println("You are here");
            System.out.println(files[i]);
      }

      f.disconnect();
} catch(Exception e) {
              
              System.out.println(e);
         }

      }
}

Thanks

Avatar of kedlu

ASKER

It worked!!
Good ;-)
f.changeWorkingDirectory( "//opt//test" );

could almost certainly be

f.changeWorkingDirectory( "/opt/test" );

btw

Avatar of kedlu

ASKER

Hello,

I'm receiving this error when running this java program from Rational TestManager but from command line it works.

ava.lang.NoClassDefFoundError org/apache/commons/net/SocketClient

I've added jar files in classpath.
Any idea?
Kedlu
>>I've added jar files in classpath.

Clearly not in Rational TestManager's classpath ;-)
Avatar of kedlu

ASKER

I had added files to Rational XDE testers classpath. There is no option to add in Rational TestManager's classpath.
But I did one thing, instead of adding in classpath to XDE tester, I imported extracted jar files into XDE tester.
So it is part of datastore now. So TestManager started working. But I did not want to do this, since this changes our architecture...but its ok!!!
Thanks CEHJ...
Kedlu
8-)