Pouria Saleh
Pouria Saleh

Reputation: 55

upload file to a specific directory in ftp server using Apache Commons Net library in java

I want to add my file to a specific directory ,not root directory in my ftp server. what can I do ? here is my java code :

FTPClient client = new FTPClient();
    String filename = "out.txt";

    // Read the file from resources folder.
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream is = classLoader.getResourceAsStream(filename);
    try  {
        client.connect("18.14.18.17");
        boolean login = client.login("root", "root");
        if (login) {
            System.out.println("Login success...");

            // Store file to server

            client.storeFile(filename, is);

            client.logout();

        }

this code adds the file to my root directory in my ftp server.

Upvotes: 0

Views: 815

Answers (0)

Related Questions