FTP connection with JAVA

Posted By Venu Thomas

Java again gives us another tool.

What is FTP?

FTP protocol that allows us to send or receive data from one point to another, be it a PC, server, or any other node that is connected to a network.

Usually when you have a web host these accounts have FTP congratulate sending files from our pc to the server that is hosting our site.

Investigating around I found a FTP client library very useful, I have tried it and going great. The library JvFTP Client provides interesting tasks, including:

  • Uploading / downloading files
  • Uploading directories recursively
  • Concurrent data transfer
  • Data transfer mode passive / active
  • Swing components to display directories
  • Components AWTpara display directories

This tool is available in jvftp and can be used in two ways, you run directly the jar, or do your own programming, including the libraries in your project.

If you want to program your own example here I leave a little guide on how you can do, let’s see …

… The first thing to do is incorporate the packages downloaded from jvftp in your project. Then you import the libraries to the class in which you make the connection:

import cz.dhl.io.*;
import cz.dhl.ftp.*;
import java.io.IOException;

Now we create the connection, the connection to prepare the data before creating access the FTP site. Let’s start with the server:

FtpConnect cn = FtpConnect.newConnect("ftp://ftp.domain.com");

ftp.domain.com value which is the server you are connecting. Each ftp account that include at least the server name, username and password. To log in using that account is something like this:

// Username
cn.setUserName("username");

// Password
cn.setPassWord("password");

Then it creates an object of type FTP, which is responsible for rendering all the information from our FTP site.

Ftp ftp1 = new Ftp();

Now the connection to the FTP site to begin processing the respective tasks

ftp1.connect(cn);

A practical example to test the connection would be to show the current directory with their files:

CoFile dir = new FtpFile(ftp1.pwd(), ftp1);

// Make a list of files that have the current directory
CoFile cfls[] = dir.listCoFiles();
if ( cfls != null )
        for (int n = 0; n < cfls.length; n++)
                    System.out.println( cfls[n].getName() + (cfls[n].isDirectory() ? "/" : ""));

Finally, there is only close the connection.

ftp1.disconnect();

Download jvftp

Happy Programming!!! ;-)

Tags: , ,

  •  
  • Share with others:

    Thanks for visiting us! If you enjoyed these icons please feel free to share them! Or if you want to know what's going on with WiseCodes.com, follow us!

    20 Responses to “FTP connection with JAVA”

    1. Good work, keep us posting, you are good writer.

    2. free tattoo ideas your flag on May 18th, 2010 at 5:42 PM
    3. It’s the first time I have heard that in Macedonia, obits are an unusual observe. You have wonderfully written the post. I have liked your way of writing this. Thanks for sharing this.

    4. putting up a privacy fence your flag on June 26th, 2010 at 12:06 AM
    5. I truly loved this brilliant article. Please continue this awesome work. Regards, Duyq.

    6. wow hacks to get to lvl 80 your flag on August 7th, 2010 at 9:25 PM
    7. Pleasure reading this!

    8. Download free psp games your flag on August 9th, 2010 at 3:09 PM
    9. Yes! thought your post is a really nice read!

    10. Fred Castle your flag on August 11th, 2010 at 11:35 PM
    11. Here in Oregon people love to cover themselves with tattoos. It’s sort of hobby with us. So I am always interested in seeing what others are doing and learning new things. Thanks for the post.

    12. Hebrew Tattoos your flag on August 16th, 2010 at 11:10 AM
    13. Thanks for the insight, Kate–now I’m definitely going to read this. *Nickeled and Dimed* was amazing, but I wasn’t sure this would be as interesting, since it’s less my field of fascination.

    14. fresno chiropractor your flag on August 20th, 2010 at 12:30 AM
    15. the evening I feel very happy on viewing the large amount accumulated. Thanks and YES ! Accepting Donations is 100 % Legit formula of making money. Watch out my blog to see how

    16. Kathey Lippa your flag on August 24th, 2010 at 2:46 PM
    17. I don’t bookmark sites but i will bookmark this! LOL!

    18. Berith your flag on August 29th, 2010 at 4:17 AM
    19. Nice site and great text.

    20. pozycjonowanie your flag on August 29th, 2010 at 3:08 PM
    21. I think this site’s structure is done well.

    22. Young Jeezy your flag on August 30th, 2010 at 2:37 PM
    23. was wondering..can I use some of your post on my site if I give you a backlink? ; )

    24. rapidshare your flag on September 1st, 2010 at 12:34 AM
    25. Thanks because of this! I’ve been searching all more than the web for that facts.

    26. zero cost commissions your flag on September 1st, 2010 at 9:38 AM
    27. Wow! That is a single of the most effective blogs I’ve at any time arrive throughout on this subject. Basically Magnificent

    28. zero cost commissions your flag on September 1st, 2010 at 3:50 PM
    29. That’s great.very helpful,thanks a lot

    30. archlord gold your flag on September 2nd, 2010 at 10:47 AM
    31. very good article,thans for your sharing

    32. archlord gold your flag on September 2nd, 2010 at 11:37 AM
    33. Well, the post is actually the freshest on this laudable topic. I concur with your conclusions and will thirstily look forward to your future updates.

    34. atlantica gold your flag on September 2nd, 2010 at 2:21 PM
    35. Well, the post is actually the freshest on this laudable topic. I concur with your conclusions and will thirstily look forward to your future updates.

    36. cabal alz your flag on September 2nd, 2010 at 3:19 PM
    37. Wow! This really is one particular of the top blogs I’ve ever occur across on this subject. Basically Amazing

    38. hyper fb traffic your flag on September 2nd, 2010 at 11:34 PM
    39. This has genuinely sparked up an thought in my brain. That is a amazing weblog publish.

    40. hyper fb traffic your flag on September 2nd, 2010 at 11:35 PM

    Leave a Reply

    Anti-Spam Protection by WP-SpamFree

    Locations of visitors to this page eXTReMe Tracker