0

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/

4

2 回答 2

1

您可能想使用ftp.connect("subdomain.example.com").

于 2013-08-09T20:13:09.927 回答
0

删除“ftp://”

此行是文本仅在此处,因此我可以提交。

于 2013-08-09T20:13:33.293 回答