Java achieve ftp download files

  For example, to download ftp:// ftp.xx.com / index.html is: 

  Import sun.net.ftp.FtpClient; 
  Import java.io. *; 
  Import sun.net .*; 

  / ** 
  * <p> Title: </ p> 
  * <p> Description: </ p> 
  * <p> Copyright: Copyright (c) 2004 </ p> 
  * <p> Company: </ p> 
  * @ Author petehero 
  * @ Version 1.0 
  * / 

  Public class ftpDown 
  ( 

  Public ftpDown () 
  ( 

  ) 
  Public static void main (String [] args) 
  ( 
  Try 
  ( 
  FtpClient fc = new FtpClient ( "ftp.xx.com"); 
  Fc.login ( "username", "888888"); 
  Int ch; 
  File fi = new File ( "c: \ \ index.html"); 
  RandomAccessFile getFile = new RandomAccessFile (fi, "rw"); 
  GetFile.seek (0); 
  TelnetInputStream fget = fc.get ( "index.html"); 
  DataInputStream puts = new DataInputStream (fget); 
  While ((ch = puts.read ())> = 0) ( 
  GetFile.write (ch); 
  ) 
  Fget.close (); 
  GetFile.close (); 
  Fc.closeServer (); 
  ) 
  Catch (IOException ex) 
  ( 

  Ex.printStackTrace (); 
  ) 

  ) 
  ) 

  If the file in a directory, to include fc.cd ( "foodir"); 

Bookmark it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Google
  • DotNetKicks
  • DZone
  • Furl
  • Netvouz

Tags: ,

Releated Articles


0 Comments to “Java achieve ftp download files”

No Comments. Send your comment.

Leave a Reply

You must be logged in to post a comment.