Steps:-

  1. Download this commons-net.jar file

  2. Extract the zip file

  3. Copy the Jar file

  4. Place the file in lib folder of your project.

  5. Right click on the project

  6. On left side of list, click on "Java Build Path"

  7. Click on Libraries tab and Click on "Add Jar"

  8. Browse the Commons-net.jar file and click on insert

Answer from Siva Charan on Stack Overflow
🌐
Apache Commons
commons.apache.org › proper › commons-net › apidocs › org › apache › commons › net › ftp › FTPClient.html
FTPClient (Apache Commons Net 3.12.0 API)
If the data connection cannot be opened (e.g., the file does not exist), null is returned (in which case you may check the reply code to determine the exact reason for failure). ... FTPConnectionClosedException - If the FTP server prematurely closes the connection as a result of the client ...
🌐
Coderanch
coderanch.com › t › 277364 › java › FTP-Client-Thread
Another FTP Client Thread (I/O and Streams forum at Coderanch)
Renamed the org folder to org2 just so it would not be read by default of the javac anymore. But now it says [/b]newftp.java:1: package org.apache.commons.net.ftp does not exist import org.apache.commons.net.ftp.FTPClient;[/b] and I cannot seem to get jar to work to extract the commons jar for some reason.
🌐
Apache Commons
commons.apache.org › proper › commons-net › apidocs › org › apache › commons › net › ftp › package-summary.html
Package org.apache.commons.net.ftp
package org.apache.commons.net.ftp · FTP and FTPS support classes · Related Packages · Package · Description · org.apache.commons.net · Common socket classes and protocol command utility classes · org.apache.commons.net.ftp.parser · FTP file listing parser classes ·
🌐
Klangbund
klangbund.eu › blog › package-org.apache.commons.net.ftp-does-not-exist.html
Klangbund
Package org.apache.commons.net.ftp does not exist · Package org.apache.commons.net.ftp does not exist The following examples show how to use org.apache.commons.io.filenameutils#separatorsToUnix() . You can vote up the ones you like or vote down the ones you don't like, and go to the original ...
🌐
Coderanch
coderanch.com › t › 401235 › java › Classpath-commons-net
Classpath Question for commons-net-1.4.0 (Beginning Java forum at Coderanch)
A simple one would be to put the Net jar file into C:\FTPTesting, and compile and run with: javac -classpath commons-net-1.4.0.jar *.java java -classpath .;commons-net-1.4.0.jar getDataFiles ... RE: #2 - To make the classpath setting permanent, you need to modify your environment variables. Go into Control Panel, double-click System, click the Advanced tab, then the Environment Variables button. Edit the variable CLASSPATH (or add it if it doesn't exist) and append ";C:\path\to\commons-net-1.4.0.jar" to the current value.
🌐
Apache Commons
commons.apache.org › proper › commons-net › apidocs › org › apache › commons › net › ftp › FTPSClient.html
FTPSClient (Apache Commons Net 3.12.0 API)
Package org.apache.commons.net.ftp · java.lang.Object · org.apache.commons.net.SocketClient · org.apache.commons.net.ftp.FTP · org.apache.commons.net.ftp.FTPClient · org.apache.commons.net.ftp.FTPSClient · All Implemented Interfaces: Configurable · public class FTPSClient extends FTPClient ·
Find elsewhere
🌐
Apache Commons
commons.apache.org › proper › commons-net › apidocs › org › apache › commons › net › ftp › FTP.html
FTP (Apache Commons Net 3.12.0 API)
Package org.apache.commons.net.ftp · java.lang.Object · org.apache.commons.net.SocketClient · org.apache.commons.net.ftp.FTP · Direct Known Subclasses: FTPClient · public class FTP extends SocketClient · FTP provides the basic the functionality necessary to implement your own FTP client.
🌐
Apache Commons
commons.apache.org › proper › commons-net › javadocs › api-1.4.1 › org › apache › commons › net › ftp › FTPClient.html
org.apache.commons.net.ftp Class FTPClient
If the data connection cannot be opened (e.g., the file does not exist), null is returned (in which case you may check the reply code to determine the exact reason for failure). ... FTPConnectionClosedException - If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421.
🌐
GitHub
github.com › apache › commons-net › blob › master › src › main › java › org › apache › commons › net › ftp › FTP.java
commons-net/src/main/java/org/apache/commons/net/ftp/FTP.java at master · apache/commons-net
When that occurs, the FTP class · * method encountering that reply will throw an {@link org.apache.commons.net.ftp.FTPConnectionClosedException}. {@code FTPConectionClosedException} is a
Author   apache
Top answer
1 of 2
2

I checked your code, it works. I've only changed file type declaration to binary, which may be not needed for XML files. Here's my complete code for reference:

package apachenet.ftp;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;

public class App {
    public static void main( String[] args ) {
        FTPClient client = new FTPClient(); 
        FileInputStream fis = null;
        try {
            client.connect(/*Util.getProductsXMLFTPServer()*/"127.0.0.1");
            client.login(/*Util.getProductsXMLFTPUser()*/"pwyrwinski", 
                    /*Util.getProductsXMLFTPPassword()*/"secret");
            client.setFileType(FTP.BINARY_FILE_TYPE); // optional
            fis = new FileInputStream(
                    new File(/* Util.getProductsXMLFTPInputFilePath() */"/home/pwyrwinski", 
                            /* Util.getProductsXMLFTPOutputFileName() */"img.png"));
            client.changeWorkingDirectory(/*Util.getProductsXMLFTPUploadPath()*/ "someDir");


            client.storeFile(/*Util.getProductsXMLFTPOutputFileName()*/"img_bis.png", fis);
            client.logout();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fis != null) {
                    fis.close();
                }
                client.disconnect();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

As you can see it's roughly the same as yours. Util class calls are replaced with raw data.

When I ran it, file /home/pwyrwinski/img.png was uploaded to {FTP_USER_ROOT}/someDir directory on ftp server with name changed to img_bis.png. I assume this is exactly what you wanted to achieve.

Let's go back to your problem.

  1. Try to check what is returned from Util.getProductsXMLFTPUploadPath() call. My guess is it's not what you're expecting - so debug it in your IDE or print it to the console.
  2. Check if path returned from Util.getProductsXMLFTPUploadPath() call starts with slash, it shouldn't.

UPDATE 1. Does direcory /home/domainname/public_html/guest exist on server?

Add following method to your class:

private static void showServerReply(FTPClient ftpClient) {
    String[] replies = ftpClient.getReplyStrings();
    if (replies != null && replies.length > 0) {
        for (String aReply : replies) {
            System.out.println("SERVER: " + aReply);
        }
    }
}

and call it after every ftp-client's method call. This will give you codes and descriptions of every command result. I suspect client.changeWorkingDirectory(...) ends with error, probably: 550 Permission Denied (or No such file or folder).

Next modification will be:

client.login(Util.getProductsXMLFTPUser(), Util.getProductsXMLFTPPassword());
System.out.println(client.printWorkingDirectory()); // added this line!

this will tell us what is current working directory after login in.

Please post your results.

2 of 2
1
FTPClient ftpClient = new FTPClient();
        try {
              System.out.println("before server connection");
            ftpClient.connect(server, port);
            System.out.println("before user name and passwod");
            ftpClient.login(user, pass);
            ftpClient.enterLocalActiveMode();

            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

            System.out.println("connection sucess");


            // windows working fine
            File secondLocalFile = new File("/home/aims/archived_reports/tes_S_000000123/test.pdf");
//            String secondRemoteFile = "/archived_reports/PermanentRecord.pdf";

//linux
          //  File secondLocalFile = new File("/archived_reports/tes_S_000009123/test.pdf");

            String secondRemoteFile = "remotefilename.pdf";
            InputStream  inputStream = new FileInputStream(secondLocalFile);

            System.out.println("Start uploading second file");

                    ftpClient.changeWorkingDirectory("/reports");// home/ftp.test/reports folder


          System.out.println("Prasent Working Directory :"+ftpClient.printWorkingDirectory());


            OutputStream outputStream = ftpClient.storeFileStream(secondRemoteFile);
                 int returnCode = ftpClient.getReplyCode();
                 System.out.println(returnCode);
            byte[] bytesIn = new byte[4096];
            int read = 1;

            while ((read = inputStream.read(bytesIn)) != -1) {
                outputStream.write(bytesIn, 0, read);
            }

System.out.println();           
            inputStream.close();
            outputStream.close();
                     boolean completed = ftpClient.completePendingCommand();
            if (completed) {
                System.out.println("The second file is uploaded successfully.");
            }
🌐
Maven Repository
mvnrepository.com › artifact › commons-net › commons-net
Maven Repository: commons-net » commons-net
July 28, 2025 - Apache Commons Net library contains a collection of network utilities and protocol implementations. Supported protocols include Echo, Finger, FTP, NNTP, NTP, POP3(S), SMTP(S), Telnet, and Whois.
🌐
Doctornearby
doctornearby.de › blog › package-org.apache.commons.net.ftp-does-not-exist.html
Doctornearby
Package org.apache.commons.net.ftp does not exist · Package org.apache.commons.net.ftp does not exist Apache Commons Net – Download Apache Commons Net Download Apache Commons Net Using a Mirror We recommend you use a mirror to download our release builds, but you must verify the integrity ...
🌐
GitHub
github.com › apache › commons-net › blob › master › src › main › java › org › apache › commons › net › ftp › FTPClient.java
commons-net/src/main/java/org/apache/commons/net/ftp/FTPClient.java at master · apache/commons-net
When that occurs, the FTP class · * method encountering that reply will throw an {@link org.apache.commons.net.ftp.FTPConnectionClosedException}. {@link FTPConnectionClosedException} is a
Author   apache
🌐
Gradle
discuss.gradle.org › help/discuss
I can´t import org.apache.commons.net.FTPClient - Help/Discuss - Gradle Forums
August 4, 2017 - Hello, I need to use de FTPClient from apache.commons.net in a Gradle proyect in Eclipse IDE, but I can´t import de class. This is my build.gradle archive: buildscript { ext { kotlinVersion = '1.1.51’ springBootVersion = ‘1.5.8.RELEASE’ } repositories { mavenCentral() maven { url ...