Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9292021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:46:53+00:00 2026-06-18T20:46:53+00:00

I am able to make a connection through FTP to Apache FTP server (

  • 0

I am able to make a connection through FTP to Apache FTP server (http://mina.apache.org/ftpserver-project/index.html). I followed the same way to make FTPS Connection. but I am getting the following error, when i run the client side program.CAn any one help me in writing client class?

here is is the code to start server.

public class FTPSServer {
public static void main(String[] args) {
    FtpServerFactory serverFactory = new FtpServerFactory();
    ListenerFactory factory = new ListenerFactory();
    // set the port of the listener
    factory.setPort(2221);
    // define SSL configuration
    SslConfigurationFactory ssl = new SslConfigurationFactory();
    ssl.setKeystoreFile(new File(
            "src/ftp/resources/cert.jks"));
    ssl.setKeystorePassword("password");
    // set the SSL configuration for the listener
    factory.setSslConfiguration(ssl.createSslConfiguration());
    factory.setImplicitSsl(true);
    // replace the default listener
    serverFactory.addListener("default", factory.createListener());

    PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();

    userManagerFactory.setPasswordEncryptor(new SaltedPasswordEncryptor());
    UserManager userManager = userManagerFactory.createUserManager();

    BaseUser user = new BaseUser();
    user.setName("test");
    user.setPassword("test");
    user.setHomeDirectory("D:\\FTP-TEST-UPLOADS");
    List<Authority> auths = new ArrayList<Authority>();
    Authority auth = new WritePermission();
    auths.add(auth);
    user.setAuthorities(auths);
    try {
        userManager.save(user);
    } catch (FtpException e1) {
        e1.printStackTrace();
    }
    serverFactory.setUserManager(userManagerFactory.createUserManager());
    // start the server
    FtpServer server = serverFactory.createServer();
    try {
        server.start();
        System.out.println("FTPs Server Started");
    } catch (FtpException e) {
        e.printStackTrace();
    }
}

}

and My Client class :

class FtpClient {
private static String ftpServerAddress = "localhost";
private static int port = 2121;
private static String userName = "test";
private static String password = "test";

public static void main(String[] args) {
    try {
        uploadFile();
        downloadFile();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

private static void downloadFile() throws IOException {
    FTPClient client = new FTPClient();
    FileOutputStream fos = null;
    boolean result;

    try {
        client.connect(ftpServerAddress, port);

        result = client.login(userName, password);

        if (!FTPReply.isPositiveCompletion(client.getReplyCode())) {
            client.disconnect();
            System.err.println("FTP server refused connection.");
            System.exit(1);
        }

        if (result == true) {
            System.out.println("Successfully logged in!");
        } else {
            System.out.println("Login Fail!");
            return;
        }

        // The remote filename to be downloaded.
        String filename = "Technolabs Logo.PNG";
        fos = new FileOutputStream(filename);

        // Download file from FTP server

        result = client.retrieveFile("receivedFiles/" + filename, fos);
        if (result == true)
            System.out.println("File was downloaded");
        client.logout();
    } catch (FTPConnectionClosedException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            client.disconnect();
            fos.close();
        } catch (FTPConnectionClosedException e) {
            System.out.println(e);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

private static void uploadFile() throws IOException {
    FTPClient client = new FTPClient();
    FileInputStream fis = null;
    boolean result;

    try {
        client.connect(ftpServerAddress, port);

        result = client.login(userName, password);

        if (!FTPReply.isPositiveCompletion(client.getReplyCode())) {
            client.disconnect();
            System.err.println("FTP server refused connection.");
            System.exit(1);
        }

        if (result == true)
            System.out.println("Successfully logged in!");
        else {
            System.out.println("Login Fail!");
            return;
        }
        client.setFileType(FTP.BINARY_FILE_TYPE);

        client.enterLocalPassiveMode();

        client.changeWorkingDirectory("/");

        File file = new File("D:/myFile.PNG");
        String testName = file.getName();
        fis = new FileInputStream(file);

        // Upload file to the ftp server
        result = client.storeFile(testName, fis);

        if (result == true) {
            System.out.println("File is uploaded successfully");
        } else {
            System.out.println("File uploading failed");
        }
        client.logout();
    } catch (FTPConnectionClosedException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            client.disconnect();
            fis.close();
        } catch (FTPConnectionClosedException e) {
            System.out.println(e);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T20:46:54+00:00Added an answer on June 18, 2026 at 8:46 pm

    u can do it through

    1 implicit SSL,
    first you need to negotiate SSL/TLS , and then the established connection

    2 explicit SSL, as mentioned here

    Also, can you use apache-commons FTPSClient ??

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to make a program that looks through a mailbox
Is it possible to connect to an SSH server through a Telnet connection? I
I was able to make a connection with a PLC to read data from
I have been able to make my photos large for single photo posts on
I am not able to make the nested elements sortable in jQuery UI. I
I am not able to make a clear decision on this one. I am
I am not able to make this out: Between eliminates use of >= and
I'm not being able to make this line work with Tk import os while(1):
I need to be able to make a tree like structure in the appengine
I want to be able to make a line graph using GTK+ but I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.