【发布时间】:2018-02-15 10:52:42
【问题描述】:
我正在尝试使用FTPSClient(真正的隐式)连接服务器,端口990,似乎连接正常,但它说找不到里面的文件PDF。
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();
}
}
我得到的错误是 java.io.FileNotFoundException 我尝试编写自 C:\ 以来的完整路径,没有它,但没有任何效果。
有人可以帮帮我吗?
谢谢。
编辑:现在可以使用了!
【问题讨论】:
-
您是否首先尝试使用旧的 ftp 客户端(当然兼容 FTPS...),例如 linux
ftp或 Windows 中的 FileZilla 来查看 FTPS 服务器实际呈现的内容? -
当然,是一个真正的服务器工作。
-
现在 PDF 正在下载,但大小为 0 KB。
-
如果找到文件但无法下载,则可能是主动与被动 FTP 模式的问题。