Solved

Ftp'ing files

Posted on 1998-03-23
4
190 Views
Last Modified: 2010-04-16
Can someone gimme some code or a nudge in the direction on how I can get a directory list from a Unix machine and then transfer files from it?? I have done this with VB and the WinInet.dll but need a COM interface and would like to do it in Java.
0
Comment
Question by:jcorbin
  • 2
4 Comments
 
LVL 6

Expert Comment

by:jpk041897
ID: 1233729
To get the directory tree only, you can use the FileDialog() method.

This method will display a modal dialog box with a tree you can navigate on.

Note, this method will not transfer the files, it will only give you a path from which you can either build a URL and trasfer the file via HTTP or UDP; or give you a full path for an FTP class to transfer the files (for which you would need FTP privilages).


 Class java.awt.FileDialog  



java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Window
                           |
                           +----java.awt.Dialog
                                   |
                                   +----java.awt.FileDialog
 
______________________________________________________________________________
 

 public class FileDialog  
 extends Dialog  

The File Dialog class displays a file selection dialog. It is a  modal dialog and will block the calling thread when the show method  is called to display it, until the user has chosen a file.  

   
See Also:  

show  

______________________________________________________________________________
 
     

   
       LOAD  

 The file load variable.  
       SAVE  

 The file save variable.  

 
     

   
       FileDialog(Frame)  

 Creates a file dialog for loading a file.  
       FileDialog(Frame, String)  

 Creates a file dialog for loading a file.  
       FileDialog(Frame, String, int)  

 Creates a file dialog with the specified title and mode.  

 
     

   
       addNotify()  

 Creates the file dialog's peer.  
       getDirectory()  

 Gets the directory of the Dialog.  
       getFile()  

 Gets the file of the Dialog.  
       getFilenameFilter()  

 Gets the filter.  
       getMode()  

 Gets the mode of the file dialog.  
       paramString()  

 Returns the parameter String of this file dialog.  
       setDirectory(String)  

 Set the directory of the Dialog to the specified directory.  
       setFile(String)  

 Sets the file for this dialog to the specified file.  
       setFilenameFilter(FilenameFilter)  

 Sets the filter for this dialog to the specified filter.  
       setMode(int)  

 Sets the mode of the file dialog.  

 
     

 LOAD

  public final static int LOAD
 
 

 The file load variable.  


 

 SAVE

  public final static int SAVE
 
 

 The file save variable.  


Hope this helps.
0
 
LVL 6

Expert Comment

by:gadio
ID: 1233730
 There is yet another approach. You can connect to this machine through FTP, using an ftp class, and navigating through the remote machine's directory, FTPing, etc. (the credits to this idea should also go to jpk). You'd perfer this approach if you want to do it non interactivly. If you want to go this direction, you can find ftp code at
http://www.oroinc.com/downloads/index.html

0
 

Author Comment

by:jcorbin
ID: 1233731
I really want to know HOW to transfer files, do I use an InputStream, a BufferedStream?? As text or binary?? using char mode or byte?? I dont care about using the dialog boxes, I am not going to use an interface, I need to build a COM component. Any help is appreciated.

 
0
 
LVL 6

Accepted Solution

by:
jpk041897 earned 70 total points
ID: 1233732
OK, the directory tree part of your question misslead me.

To transfer files using Java I would suggest you use TCP/IP using Binary file transfer, TCP to insure Quality of Service and Binary to allow you to transfer any type of file..

As gadio suggests, the simplest approach is to use FTP, you can download both free FTP client classes and FTP servers from several sources. The disadvantage of this scheme is that access to files on the server are restricted by the browser's security sandbox and can only access files under the web servers directory structure. FTP furter limits you to a public directory structure that should be completly independant of the the rest of the file system

The advantage of defining your own streams is that your server code is not limited in any way, so you could transfer any file which the underlying OS's security allows you to read. The disadvantage is that it requires a lot more code.

For sample code on accessing DB's via sockets and Client Server take a look at Chapter 34 of:

Tricks of the  Java Programming Gurus
by Glenn L. Vanderburg. et al.

For a more simple type of  data transfer have a look at Chapter 6 of:

JAVA Expert Solutions
by Mark Wutka, et. al.

oth books may be read on line at:

http://www.mcp.com 

under the Personal Library URL,  Programming section.  Both books vhave good explanations and good sample code that should get you up and running in no time.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 95
Html Table Looping (part 2) 5 34
java mysql insert application 14 41
glassfish admin console 1 16
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

685 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