Answer the question
In order to leave comments, you need to log in
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
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();
});
});
$('.success span').click(function(){
$(this).parents("div.success").fadeOut();
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question