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

  • SEARCH
  • Home
  • 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 9196979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:58:14+00:00 2026-06-17T21:58:14+00:00

Using Apache Commons Net 3.2, my program is connecting to an FTP server and

  • 0

Using Apache Commons Net 3.2, my program is connecting to an FTP server and downloading files from it.

What it should be able to do, however, is to read the files on the server WITHOUT downloading them.

Is this even possible?

It’s just that the server contains lots of personal information, SSN, phone, email, etc, and only specific people with the right password should be able to access them.

No one should be able to download anything from the server, at least not without the highest level of permissions granted in my program!

So far I have an FTPFile [] with all the data files on the server.

I want to loop through them, see if they have the current user’s name on it (meaning they’re allowed to view this person/file), and if so, add their data to an ArrayList .

Any tips?

import java.io.File;
import java.io.FileOutputStream;
import java.util.List;
import java.util.Arrays;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;

public class Server {
    private static final String server = "/server";
    private static final String host = "00.000.0.0";
    private static final String user = "username";
    private static final String pass = "password";
    private static List <FTPFile> data;
    private static FTPClient ftp = new FTPClient ();

    public static void load (String folder) {
        try {
            // Connect to the SERVER
            ftp.connect(host, 21);
            if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
                System.out.println("Could not connect to the server.");
                return;
            }

            // Login to the SERVER
            ftp.enterLocalPassiveMode();
            if (!ftp.login(user, pass)) {
                System.out.println("Could not login to the server.");
                return;
            }

            // Get DATA from the SERVER
            System.out.println(server + "/" + folder);
            data = Arrays.asList(ftp.listFiles(server + "/" + folder));
            System.out.println(data.size());
            for (int f = 0; f < data.size(); f++)
                System.out.println(data.get(f).getName());

            // Disconnect from the SERVER
            ftp.logout();
            ftp.disconnect();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String read (FTPFile file) {
        try {
            String name = file.getName();
            File tempFolder = new File ("temp/" + name);
            tempFolder.mkdirs();

            // Create a TEMPORARY DATA FILE
            File tempFile = new File (tempFolder.getAbsolutePath() + "/data");
            System.out.println(tempFile.getAbsolutePath());
            tempFile.createNewFile();
            tempFile.deleteOnExit();

            // Get ready to DOWNLOAD DATA from the SERVER
            FileOutputStream out = new FileOutputStream (new File (name));
            ftp.connect(host, 21);
            ftp.login(user,  pass);

            // DOWNLOAD and DISCONNECT
            ftp.retrieveFile(name, out);
            out.close();
            ftp.logout();
            ftp.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ""; // This should return a String with data read from the file
    }
}
  • 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-17T21:58:15+00:00Added an answer on June 17, 2026 at 9:58 pm

    If you want to “read” (as in inspect its content) a file you have to download, i.e. transfer its contents from the server to the client. There is no way around it, when you are restricted to a client sided solution.

    In general it is a bad idea to check user permissions in the client only. If a malicious user has the correct credentials to access the server (that could be extracted from the client), he can circumvent the client sided authorization, rendering it useless.

    Authentication and authorization of users should always occur server sided.

    In your example you could consider the creation of different users on the ftp server and appropriate rights to access, read and write files / directories.

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

Sidebar

Related Questions

I am using apache commons-net for downloading a file from an FTP server. That
I'm using Apache's commons-net-2.2.jar to download a batch of files from a FTP server,
I'm using org.apache.commons.net.ftp.FTPClient to communicate with an ftp server via an android app I'm
Hay Guy, I'm using org.apache.commons.net.nntp to connect to a nntp server, however running a
I'm using the FTP library provided by Apache (commons-net). I want to check if
Weblogic 10.3.1.0 is using com.bea.core.apache.commons.net_1.0.0.0_1-4-1.jar... I want to use commons-net-2.0.jar from my code. How
I have code to upload a file to a server. import org.apache.commons.net.ftp.FTPClient; import java.io.File;
I'm using apache's commons-net FTPClient to upload files. I'm using storeFileStream method. This works
We are using the following Apache Commons Net FTP code to connect to an
I implemented a FTPS client (FTP over SSL/TLS) in java using the apache.commons.net -framework.

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.