Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Ftp'ing files

Posted on 1998-03-23
4
Medium Priority
?
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 280 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

661 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