Solved

Ftp'ing files

Posted on 1998-03-23
4
160 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:

760 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

22 Experts available now in Live!

Get 1:1 Help Now