Hi!
If I run the code shown below from my local machine, where the FTP server is installed, then everything works correctly. However, if I try to run it from some other machine, then the message "Cannot connect to the FTP server!" appears.
Settings of my FTP Server are shown in the attached image.
I have absolutely no idea about this problem. Please, help me with some advise. What could be wrong and what should I do to fix this problem?
private void openFile(String directoryPath, String fileName) {
FTPClient client = new FTPClient();
FileOutputStream fos = null;
File file = new File(fileName);
try {
client.connect(this.url);
client.login(this.login,this.password);
fos = new FileOutputStream(fileName);
boolean b = client.retrieveFile(directoryPath + fileName, fos);
if (!b) {
JOptionPane.showMessageDialog(null, "Cannot access the file " + fileName + "!", "Warning", JOptionPane.WARNING_MESSAGE);
} else {
try {
Desktop.getDesktop().open(file);
}
catch (IOException ioe) {
JOptionPane.showMessageDialog(null, "Cannot open the file " + fileName + "!", "Warning", JOptionPane.WARNING_MESSAGE);
}
}
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Cannot connect to the FTP server!", "Warning", JOptionPane.WARNING_MESSAGE);
} finally {
try {
if (fos != null) {
fos.close();
}
client.disconnect();
if (file.exists()) {
file.deleteOnExit();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}