Display PDF from FTP

I am trying to retrieve a PDF file from my FTP and display it on an IFrame, but i am having some trouble getting it to work.
Here is what i have done:

MiscWebUtils m = new MiscWebUtils();
FTPClient ftpClient = m.iniciarFTP(FTP.BINARY_FILE_TYPE, FTP.STREAM_TRANSFER_MODE);

ftpClient.enterLocalPassiveMode();

String pastaCliente = "/PORTAL/FATURAS_CLIENTES/"
                            + clienteBusca.getDocumento().replaceAll("[^0-9]+", "");
//Here i create a temp file to store the PDF in.
File f = File.createTempFile("faturatmp", ".pdf");
OutputStream fOutputStream = new BufferedOutputStream(new FileOutputStream(f));
ftpClient.retrieveFile(pastaCliente + "/" + selected.get().getArquivoFatura(), fOutputStream);
MiscWebUtils.verRespFTP(ftpClient);

//I convert the file inputstream to a StreamResource.
StreamResource streamResource = new StreamResource(
     "fatura.pdf", () -> {
             try {
                return new FileInputStream(f);
             } catch (FileNotFoundException e) {
                return null;
             }
      });

// Then, i set up the registration and add the PDF to an IFrame.   
StreamRegistration registration = VaadinSession.getCurrent().getResourceRegistry().registerResource(streamResource);
IFrame viewer = new IFrame(registration.getResourceUri().toString());

// And finally, i add the IFrame to a Dialog.
Dialog d = new Dialog(viewer);

The result i get from this, is a connection refused.
image.png

Does the FTP download work? can you open the temp file?

Hello! I did some checking and the pdf is not downloading properly

ill fix that and come backl if needed, ty

Hello again! My code was missing fOutputStream.close();. it was a lack of attention of me, now the PDF displays properly.