Solved

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

Posted on 2004-09-14
26
469 Views
Last Modified: 2013-12-05
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
0
Comment
Question by:kedlu
  • 12
  • 12
  • 2
26 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12056800
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();
0
 

Author Comment

by:kedlu
ID: 12059836
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12060267
That's 3 OSs you've named. Are we talking about the same LAN?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 24

Expert Comment

by:sciuriware
ID: 12061593
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!
0
 

Author Comment

by:kedlu
ID: 12067100
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12067186
You said you were on a Windows box. Can you do

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

?
0
 

Author Comment

by:kedlu
ID: 12067928
No I can't. I get following erro:

The network path was not found.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 12067962
How about zebra? You need to be able to access them remotely. Else you need to get an FtpClient that supports deletion

http://sourceforge.net/search/?type_of_search=soft&exact=1&forum_id=0&group_id=0&atid=0&words=java+ftp+client&Search=Search
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12072124
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!
0
 

Author Comment

by:kedlu
ID: 12117640
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12118060
You tell us which client you're using. You'll probably find there are examples in the download
0
 

Author Comment

by:kedlu
ID: 12118195
I'm using FTP which is installed on windows 2000. I did not install that. I guess it came with Windows 2000.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12118241
I'm talking about a *Java* client
0
 

Author Comment

by:kedlu
ID: 12118260
Oops...ok... java 1.3.1
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12118313
So - you need to decide on a Java client. The sdk doesn't really support ftp
0
 

Author Comment

by:kedlu
ID: 12118351
So which java client will support ftp?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12118389
I posted a link earlier
0
 

Author Comment

by:kedlu
ID: 12125164
Let me try one of them. I will be back after trying...thanks!!
0
 

Author Comment

by:kedlu
ID: 12195522
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

0
 

Author Comment

by:kedlu
ID: 12195789
It worked!!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12197811
Good ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12197817
f.changeWorkingDirectory( "//opt//test" );

could almost certainly be

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

btw

0
 

Author Comment

by:kedlu
ID: 12230836
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12231143
>>I've added jar files in classpath.

Clearly not in Rational TestManager's classpath ;-)
0
 

Author Comment

by:kedlu
ID: 12231805
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12231931
8-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to execute a Python program and gather return output in Java 2 40
lunix and unix command 21 86
Using sort and uniq to pare down large syslog 6 51
printf performancy 11 68
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question