Greetings.
I have this weird problem. In the project I'm currently working on, I need to upload a file to an FTP site. I wrote a lot of programs that do this before, and they did a great job. But this particular site gives me problems. When I try to download a file from a program, I get the following:
java.net.UnknownHostException: ftp://site.com
However, when I try to connect to the same site from a browser (Chrome, IE) or from a Windows browser, I can find the site and log in. I was tired of posting a photo, but I was forbidden to do this because I am new.
So now I'm at a standstill. If I cannot connect to the windows, I can assume that this is an FTP server problem. This happens to me only from a Java program. And I also know that my code works the way I used in many cases before. Here is the code I'm using:
public void uploadFile(String fileName) throws Exception {
FileTransferClient ftpClient = null;
try {
ftpClient = new FileTransferClient();
ftpClient.setRemoteHost(gv.ftpHost);
ftpClient.setRemotePort(21);
ftpClient.setUserName(gv.ftpUserName);
ftpClient.setPassword(gv.ftpPassword);
ftpClient.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.PASV);
ftpClient.connect();
ftpClient.uploadFile(gv.irp + fileName, fileName, WriteMode.OVERWRITE);
}
catch (Exception e) {
throw new Exception("Error occured in uploadFile()\n" + e);
}
finally {
if (ftpClient != null) {
if (ftpClient.isConnected()) {
ftpClient.disconnect();
}
ftpClient = null;
}
}
}
I am using the edtFTPj library. My environment is Eclipse Helios (32-bit) on Java 1.6 (32 bits), running on a 64-bit Windows 7 machine.
Any understanding of this issue will be clear. Thank you for your time.
source
share