Greetings folks.
I have this weird problem. In the project I'm working on now, I need to upload a file to a FTP site. I have written many programs that do this before and they have worked just fine. But this particular site is giving me trouble. When I try to upload the file from the program, I get this to be specific:
java.net.UnknownHostException: ftp://site.com
However when I try to connect to the same site from within a browser (Chrome, IE) or from windows explorer, I'm able to find the site and login just fine. I tired posting a picture, but I was prevented from doing so as I'm a newbie.
So I'm stumped now. If I could not connect from windows, then I can assume it is a FTP server issue. This happens to me only from the Java program. And I also know that my code works as I have used in numerous occasions before. Here is the code I use:
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 use the edtFTPj library. My environment is Eclipse Helios (32 bit) on Java 1.6 (32 bit) running from a Windows 7 64 bit machine.
Any insight on resolving this will be greatly appreciated. Thanks for your time.
The message
java.net.UnknownHostException: ftp://site.com
suggests quite strongly that you're trying to open a connection to a host named "ftp://site.com", which is unfortunately a url rather than a host name and is thus not found.
Try changing your code so that it connects to "site.com".