FTP file transfer in Java using Apache Commons Net

The following sample code works well with Java 1.5 and Apache Commons Net 1.4.1

import org.apache.commons.net.ftp.*;
boolean ftpTransfer(String localfile, String destinationfile)
	String server = "ftp.domain.com";
	String username = "ftpuser";
	String password = "ftppass";
		FTPClient ftp = new FTPClient();
		if(!ftp.login(username, password))
			return false;
		int reply = ftp.getReplyCode();
		if (!FTPReply.isPositiveCompletion(reply))
			return false;
		InputStream in = new FileInputStream(localfile);
		boolean Store = ftp.storeFile(destinationfile, in);
	catch (Exception ex)
		return false;
	return true;

17 thoughts on “FTP file transfer in Java using Apache Commons Net

  1. Hello there! This article couldn’t be written any better!
    Reading through this article reminds me of my previous roommate!
    He always kept preaching about this. I will send this post
    to him. Fairly certain he’ll have a very good read. Thank you for sharing!


  2. Participants were able to proceed to the next drum-break only after they had heard the whole of the previous drum-break.
    Or, even worst, doo you experience embarrassed sending them to the technological innovation obsessed fellows
    that you have as close friends. Their unique, close-knit bond undoubtedly transcends the norrmal
    “lifespan” of the more popular groups.


  3. My brother suggested I would possibly like this website.
    He was entirely right. This submit truly made my day.

    You cann’t consider just how so much time I had spent
    for this information! Thank you!


  4. You really make it seem really easy with your presentation but I in finding this matter to be actually something that I believe I’d never understand.
    It seems too complicated and very extensive for me.

    I am having a look forward on your subsequent put up,
    I’ll try to get the grasp of it!


  5. If the desired domain is registered already then check the Whois details in network solutions for the registered owner details.
    Therefore, owners should never be put off
    by a low cost price in assuming that the hosting service is of poor quality;
    this is simply not the case with cloud hosting. There
    are different features from different hosting companies that offer different prices.


  6. My spouse and i love, result in I stumbled upon just what I used to be having a look for. You might have concluded this Five day extensive seek out! Our god Thanks a lot dude. Employ a awesome morning. Cya


  7. Hey would you mind stating which blog platform you’re working with? I’m going to start my own
    blog soon but I’m having a tough time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something completely unique.
    P.S Sorry for getting off-topic but I had to ask!


  8. I have used above code, but it is not printing any output on the console. Can you please explain the above code and how to give the path of the destination file and how to give the server name. Here am giving server name as url.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s