I am trying to write a JAVA program to connect to FTP. I have downloaded .JAR file from apache and added it to LIB folder in my project.
When I try to connect to the FTP as per code below, I get java.net.UnknownHostException
If I use
ftp:// subdomain.example.com - java.net.UnknownHostException
ftp.subdomain.example.com - java.net.UnknownHostException
ftp:// example.com - java.net.UnknownHostException
ftp.example.com - It works!
All my files are at ftp:// subdomain.example.com/ and I don't want to change anything in my FTP.
If I try to open ftp:// subdomain.example.com/ in Google Chrome browser, it asks for my username and password.
import java.io.IOException;
import java.net.SocketException;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
public class ConnectToFTP {
public static final void main(String[] args) throws SocketException, IOException {
FTPClient ftp = new FTPClient();
try {
ftp.connect("ftp://subdomain.example.com");
} catch (Exception e) {
System.out.println("The Error : " + e.toString());
}
System.out.println("login: "+ftp.login("username", "password"));
}
}
Can you please help me in getting connection to ftp://subdomain.example.com/