F
F
Fedor unknown2021-09-15 07:44:24
Java
Fedor unknown, 2021-09-15 07:44:24

How to download file from FTP server in java?

Hello!
Using java code, I need to connect to the server and download the file.

I have an FTP SERVER: ftp.example.com username = example password = 12345

I can connect to the server, but I can't download a file from there, what am I doing wrong?

java code:

public class FtpConnectDemo {
    public static void main(String[] args) throws IOException {

        String server = "ftp.example.com";
        int port = 21;
        String username = "example";
        String password = "12345";

        FTPClient ftpClient = new FTPClient();

//         connect and download
        try {

            ftpClient.connect(server, port);
            ftpClient.login(username, password);
            ftpClient.enterLocalPassiveMode();
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

            // APPROACH #1: using retrieveFile(String, OutputStream)
            String remoteFile1 = "/BunkerEastProdProxiesResFile_bebluecoat2_2021-09-15-00-30-02.txt";
            File downloadFile1 = new File("C:/Users/omur/Desktop/myFile.txt");
            OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(downloadFile1));
            boolean success = ftpClient.retrieveFile(remoteFile1, outputStream1);
            outputStream1.close();

            if (success) {
                System.out.println("File #1 has been downloaded successfully.");
            }

        } catch (IOException ex) {
            System.out.println("Error: " + ex.getMessage());
            ex.printStackTrace();
        } finally {
            try {
                if (ftpClient.isConnected()) {
                    ftpClient.logout();
                    ftpClient.disconnect();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }


        }
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
ixon, 2014-09-12
@dmitryosipov

$(".close").click(function() {
$(".success").hide();
});

C
Creada, 2014-09-12
@Creada

In the very top function you have:

$('.success span, .warning span, .attention span, .information span').live('click', function() {
  $(this).parent().fadeOut('slow', function() {
  $(this).remove();
  });
});

Closes the image itself, not the parent div .
For $('.success span') do:
$('.success span').click(function(){
$(this).parents("div.success").fadeOut();
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question