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 6 of 6

Thread: Uploading File to server ( Apache.commons.net)

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Uploading File to server ( Apache.commons.net)

    Hello, it's my first post, so if it is wrong place to write I apologize in advance.
    I have problem with uploading file to server which I've been trying to solve for few days, but that was been way to nowhere.
    Code looks like that, and I am succesfully logging into server, but I can't do anything more.
    Java Code:
    FTPClient client = new FTPClient();
    String fileName = "regulamin.txt";
    FileInputStream fis = null;
    int reply;
        try {
            fis = new FileInputStream(fileName);
     
            client.connect("ftp.polishtennis.web44.net");
     
            System.out.println(client.getReplyString());
     
            reply = client.getReplyCode();
     
             if(!FTPReply.isPositiveCompletion(reply)) {
                    client.disconnect();
                    System.err.println("FTP server refused connection.");
                    System.exit(1);
                  }
     
            client.login("user", "pass");
            System.out.print(client.getReplyString());
     
            client.changeWorkingDirectory("/public_html");
            System.out.println(client.getReplyString());
     
            client.storeFile("regulamin.txt", fis);
            System.out.println(client.getReplyString());
     
            client.logout();
            System.out.println(client.getReplyString());
    And I always get errors while uploading, listing files or anything its upsetting-.-"
    //server replies
    220---------- Welcome to Pure-FTPd [privsep] ----------
    220-You are user number 26 of 500 allowed.
    220-Local time is now 05:13. Server port: 21.
    220-This is a private system - No anonymous login
    220 You will be disconnected after 3 minutes of inactivity.

    230-OK. Current restricted directory is /
    230-8 files used (0%) - authorized: 10000 files
    230 1687 Kbytes used (0%) - authorized: 1536000 Kb
    250 OK. Current directory is /public_html
    //exception
    java.net.SocketException: Software caused connection abort: recv failed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
    at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
    at sun.nio.cs.StreamDecoder.read(Unknown Source)
    at java.io.InputStreamReader.read(Unknown Source)
    at java.io.BufferedReader.fill(Unknown Source)
    at java.io.BufferedReader.read(Unknown Source)
    at org.apache.commons.net.io.CRLFLineReader.readLine( CRLFLineReader.java:58)
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java :310)
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java :290)
    at org.apache.commons.net.ftp.FTP.sendCommand(FTP.jav a:474)
    at org.apache.commons.net.ftp.FTP.sendCommand(FTP.jav a:547)
    at org.apache.commons.net.ftp.FTP.port(FTP.java:872)
    at org.apache.commons.net.ftp.FTPClient._openDataConn ection_(FTPClient.java:667)
    at org.apache.commons.net.ftp.FTPClient.__storeFile(F TPClient.java:551)
    at org.apache.commons.net.ftp.FTPClient.storeFile(FTP Client.java:1704)
    at Socket.main(Socket.java:42)
    Am I doing something wrong?
    I would be grateful for any help.


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Uploading File to server ( Apache.commons.net)

    It's a Socket exception, clearly means that either you are behind firewall or your sockets can not listen/communicate properly.

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Uploading File to server ( Apache.commons.net)[solved]

    Oh dude, you are fu*&%^g awesome, ahh, I've wasted circa 40 hours over that issue and you've solved it in few seconds. I've just forget to add exception in window's firewall. But it doesn't explain, why program could connect to server but file transfer was impossible... why does windows behave like that?

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Uploading File to server ( Apache.commons.net)[solved]

    Quote Originally Posted by quirell View Post
    Oh dude, you are fu*&%^g awesome, ahh, I've wasted circa 40 hours over that issue and you've solved it in few seconds. I've just forget to add exception in window's firewall. But it doesn't explain, why program could connect to server but file transfer was impossible... why does windows behave like that?
    If you will read the exception trace, you will find the answer yourself.

  5. #5
    Member
    Join Date
    Dec 2011
    Posts
    50
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: Uploading File to server ( Apache.commons.net)

    Firewall is the surfaced problem, the underlying problem is you should connect to the FTP server using local passive mode.

  6. #6

    Default Re: Uploading File to server ( Apache.commons.net)

    This article explains how to upload files to FTP server using Apache commons net in depth:

    How to upload files to FTP server

Similar Threads

  1. need help with 'org.apache.commons.net.ftp.FTPClient'
    By rtumatt in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 22nd, 2013, 07:02 PM
  2. [SOLVED] Uploading a Java Applet embedded in HTML to a Web server
    By wizdom in forum What's Wrong With My Code?
    Replies: 20
    Last Post: December 3rd, 2011, 10:13 AM
  3. problem with uploading an image to server
    By jzarapsa in forum Java Servlet
    Replies: 3
    Last Post: October 17th, 2011, 09:29 PM
  4. Apache XML-RPC server creation problem
    By r0x in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 10th, 2011, 09:52 AM
  5. Apache server restsrting problem
    By Gaurav Gupta in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 13th, 2011, 05:50 AM