Solved

Ftp'ing files

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
json example 39 132
groovy example issue 10 90
GUI builder for Eclipse? 8 27
oracle 11g 23 49
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…
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

920 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

15 Experts available now in Live!

Get 1:1 Help Now