Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: need help with 'org.apache.commons.net.ftp.FTPClient'

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need help with 'org.apache.commons.net.ftp.FTPClient'

    I have this code which uploads to my ftp server fine however i am unable to return a value of how far the file has uploaded, any help would be appreciated thanks.

    code:
    import org.apache.commons.net.ftp.FTPClient;
    import org.apache.commons.net.ftp.FTPReply;

    import java.io.FileInputStream;
    import java.io.IOException;
    import java.net.SocketException;

    public class FileUpload {


    public FileUpload()
    {

    }

    public static void main(String[] args) {
    FTPClient ftp = new FTPClient();
    try {

    ftp.connect("localhost");
    ftp.login("user","pass");

    int reply = ftp.getReplyCode();
    if(FTPReply.isPositiveCompletion(reply)){
    System.out.println("Connected Success");
    }else {
    System.out.println("Connection Failed");
    ftp.disconnect();

    }

    FileInputStream in = null;
    try {
    in = new FileInputStream("/home/matt/Desktop/testfile.txt");
    ftp.storeFile("/home/matt/testfile.txt",in);
    ftp.disconnect();
    }catch(IOException e){
    System.out.println(e);
    }

    } catch (SocketException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }
    }

  2. #2
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: need help with 'org.apache.commons.net.ftp.FTPClient'

    If you're using any sort of GUI you can use the ProgressMonitorInputStream i am thinking to display how much of the file has been uploaded. Hopefully that helps or try to make the question little more clear for me to understand. how big is the file and all that good stuff.

    --- Update ---

    If i understand what you are asking for you can use this line to do it:

    boolean done = ftpClient.storeFile(fileName, inputStream);
    inputStream.close();
    if (done) {
    System.out.println("The first file is uploaded successfully.");
    }

    Let me know if that works.

Similar Threads

  1. Need Hellp!! problem with org.apache.struts.actions.DownloadAction.copy
    By nikshri in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 6th, 2010, 01:06 AM
  2. Problem running Apache tomcat 6.0 using i.p. address
    By nakul in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: April 8th, 2010, 07:58 AM
  3. org.apache.derby does not exist?
    By disclaimer in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 30th, 2010, 04:58 PM
  4. apache-jboss
    By supriya ramjee in forum Web Frameworks
    Replies: 0
    Last Post: August 12th, 2009, 05:37 AM