Solved

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

Posted on 2004-09-14
26
464 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now