简体   繁体   中英

Java FTP over TLS/SSL (FTPS- Implicit) Server in Java - Several Error

I am trying to connecting a server with FTPSClient (true implicit), port 990, and it seems the connection is ok, but it says that the file PDF inside cannot be found.

     String protocol = "TLS"; // TLS / SSL 
    boolean isImpicit = true; 
    int timeoutInMillis = 3000; 

    FTPSClient client = new FTPSClient(protocol, isImpicit); 

    client.setDataTimeout(timeoutInMillis); 
    client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); 

    try 
    { 
        int reply; 

        client.connect(server, port); 

        client.login(user, pass); 
        client.setFileType(FTP.BINARY_FILE_TYPE); 

        client.execPBSZ(0); 
        client.execPROT("P"); 

        System.out.println("Connected to " + server + "."); 

        reply = client.getReplyCode(); 

        if (!FTPReply.isPositiveCompletion(reply)) 
        { 
            client.disconnect(); 
            System.err.println("FTP server refused connection."); 
            System.exit(1); 
        } 

        client.listFiles(); 

        boolean retrieved = client.retrieveFile(Constantes.DIRECCION_FTP_PDF_FACTURAS + nombre_factura, new FileOutputStream(Constantes.DIRECCION_FTP_LOCAL_DESCARGAS + nombre_factura)); 

    } 
    catch (Exception e) 
    { 

        if (client.isConnected()) 
        { 
            try 
            { 
                client.disconnect(); 
            } 
            catch (IOException ex) 
            { 
                ex.printStackTrace(); 
            } 
        } 
        System.err.println("Could not connect to server."); 
        e.printStackTrace(); 
        return; 
    } 
    finally 
    { 
        System.out.println("# client disconnected"); 
        client.disconnect(); 
    } 

}

The error I got is java.io.FileNotFoundException I tried writing the full path since C:\\ , and without it, but nothing works.

Anybody can help me?

Thanks.

EDIT: IT WORKS NOW!

The path "Program Files" contains a space and maybe FileInputStream does not manage to resolve it properly. May give it a try to put your folder to "C:/Temp/" and test it again.

Where does this FileNotFoundException happen exactly?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM