I need to download a file from ftp which uses basic authentication.
I tried setting the Authenticator
class like it is pointed out here: Authenticated HTTP proxy with Java but I cant seem to get it to authenticate.
Every time I download the file, it always says invalid username or password.
Am I doing something wrong? How can I be sure that the authenticator is called?
Here is the code I am using to download the file:
Authenticator.setDefault(
new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
username, password.toCharArray());
}
}
);
PrinterJob job = PrinterJob.getPrinterJob();
for (PrintService printer : PrintServiceLookup.lookupPrintServices(null, null))
{
if(printer.getName().equalsIgnoreCase(targetPrinters[i]))
{
job.setPrintService(printer);
}
}
PDDocument doc;
URL url = new URL("ftp", "10.16.20.73", 21, file);
doc = PDDocument.load(url);
doc.silentPrint(job);
i++;