Link to home
Start Free TrialLog in
Avatar of rzvika3
rzvika3

asked on

ftp commands

Hi
I want to create an ftp application using Java.
Can i find a ready one?
If not, where can i find how to invoke ftp commands?

ASKER CERTIFIED SOLUTION
Avatar of gadio
gadio

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gadio
gadio




                           import sun.net.*;
                           import sun.net.ftp.*;
                           import java.io.*;


                           public class ftp_utility {

                               public ftp_utility () {
                                   FtpClient fcMyFtp = new FtpClient();

                                   try {
                                       int ch;
                                       fcMyFtp.openServer("myftpsite");
                                       fcMyFtp.login("myname","mypassword");
                                       TelnetInputStream tisList = fcMyFtp.list();
                                       while( (ch = tisList.read()) != -1 ) System.out.print((char)ch);
                                       // ... other stuff.
                                       fcMyFtp.cd("temp");
                                       fcMyFtp.binary();

                                       // writing a file:
                                       FileInputStream fis = new FileInputStream( "/home/gadio/temp/tempfile
                           " );
                                       TelnetOutputStream  tos = fcMyFtp.put("tempfile.new");
                                       byte buffer[] = new byte[1000];
                                       int len;
                                       while( (len = fis.read(buffer)) != -1 ) {
                                           tos.write(buffer,0,len);
                                       }
                                       fis.close();
                                       tos.close();

                                       // reading a file:
                                       FileOutputStream fos = new FileOutputStream( "/home/gadio/temp/tempfi
                           le.read" );
                                       TelnetInputStream   tis = fcMyFtp.get("tempfile.new");
                                       while( (len = tis.read(buffer)) != -1 ) {
                                           fos.write(buffer,0,len);
                                       }
                                       tis.close();
                                       fos.close();
                                   } catch( IOException e ) {
                                       e.printStackTrace();
                                   }
                               }

                               public static void main(String args[]) {
                                   ftp_utility f = new ftp_utility();
                               }
                           }
Hope that helps. If you decide that this suites you I'll give you the full API to the FtpClient class.
Looks cool man.
Avatar of rzvika3

ASKER

excellent!!!
BUT, i can't see the source code ;-)
do you know about such application that i can use its source code?

Gadio:
------
can you send me the full api? my email is: s2794372@t2.technion.ac.il

Pyxide:
-------
i create a question for you, thank you!
(if you can, tell me how i can get its source code by the classes)
use jad the best and the fastest java Decompiler on Planet Earth
http://www.geocities.com/SiliconValley/Bridge/8617/jad.html