我正在尝试使用 FTP 将文件上传到大型机服务器。我的代码在下面
FTPClient client = new FTPClient();
InputStream in = null;
FileInputStream fis = null;
try {
client.connect("10.10.23.23");
client.login("user1", "pass123");
client.setFileType(FTPClient.BINARY_FILE_TYPE);
int reply ;
reply = client.getReplyCode();
System.out.println("Reply Code:"+reply);
if(FTPReply.isPositiveCompletion(reply)){
System.out.println("Positive reply");
String filename ="D:\\FILE.txt";
in = new FileInputStream(filename);
client.storeFile("FILE.TXT", in);
client.logout();
fis.close();
} else {
System.out.println("Negative reply");
}
} catch(final Throwable t){
t.printStackTrace();
}
代码在client.storeFile("FILE.TXT", in);
我无法调试。请提出方法/解决方案。
最佳答案
首先是 Lukas 所说的 fis 为空,但我还有很多其他问题。什么是 FTP 客户端?它不是 sun.net.ftp.FtpClient,因为该类没有 store()
方法。其他需要考虑的事情是登录大型机,在我工作的地方,你不能不先登录就从大型机上抓取文件。可以考虑更多的事情,但让我们从这里开始。
关于java - 使用 Java、Apache Common Net 将文件通过 FTP 传输到大型机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4569787/