FTP4J를 사용하여 FTP에 연결할 수 없음 (Unable to connect to FTP using FTP4J)


문제 설명

FTP4J를 사용하여 FTP에 연결할 수 없음 (Unable to connect to FTP using FTP4J)

특정 파일을 다운로드하기 위해 FTP 서버에 연결해야 하는 프로그램을 작성 중입니다. 이 작업을 수행하기 위해 FTP4J 라이브러리를 사용하고 있지만 몇 가지 문제가 있습니다.

지금까지는 다음과 같습니다.

    if ("Dataset FTP location".equals(link.text())) {

        String FTPURL = link.attr("href");

        FTPClient client = new FTPClient();

        try {
            client.connect(FTPURL);
        } catch (FTPIllegalReplyException e) {
            e.printStackTrace();
        } catch (FTPException e) {
            e.printStackTrace();
        }

FTP의 URL은 ftp://ftp.pride.ebi.ac.uk/ 자존심/data/archive/2015/10/PXD002829

그러나 프로그램을 실행하면 다음과 같은 결과가 나타납니다.

Exception in thread "main" java.net.UnknownHostException: ftp://ftp.pride.ebi.ac.uk/pride/data/archive/2015/10/PXD002829
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at it.sauronsoftware.ftp4j.FTPConnector.tcpConnectForCommunicationChannel(FTPConnector.java:208)
    at it.sauronsoftware.ftp4j.connectors.DirectConnector.connectForCommunicationChannel(DirectConnector.java:39)
    at it.sauronsoftware.ftp4j.FTPClient.connect(FTPClient.java:1036)
    at it.sauronsoftware.ftp4j.FTPClient.connect(FTPClient.java:1003)
    at Main.main(Main.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

도움을 주시면 감사하겠습니다.

또한 서버에 대한 로그인이 없으며 파일의 공개 저장소일 뿐입니다. 이것이 내가 일을 하는 방식에 영향을 줍니까?


참조 솔루션

방법 1:

You need to split off the path and create a url that looks like:

ftp.pride.ebi.ac.uk

In answer to your comment you need to do something like this:

    String ftpPath = "ftp://ftp.pride.ebi.ac.uk/pride/data/archive/2015/10/PXD002829";
    URL url = new URL(ftpPath);
    String host = url.getHost();
    FTPClient client = new FTPClient();
    try {
        client.connect(host);
        client.login("anonymous", "anonymous");
        FTPFile[] list = client.list(url.getPath());
        for (FTPFile f : list) {
            // Instead of printing out the file download it. See
            // http://www.sauronsoftware.it/projects/ftp4j/manual.php#14
            System.out.println(f); 
        }
    } catch (FTPIllegalReplyException e) {
        e.printStackTrace();
    } catch (FTPException e) {
        e.printStackTrace();
    }

(by user2320239rainkinz)

참조 문서

  1. Unable to connect to FTP using FTP4J (CC BY‑SA 2.5/3.0/4.0)

#ftp4j #FTP #java






관련 질문

FTP4J를 사용하여 FTP에 연결할 수 없음 (Unable to connect to FTP using FTP4J)







코멘트