我在我的 Java 项目中使用 Apache 的 FTPClient 和 FTPServer 库。服务器和客户端在同一台机器上。
我的 FTPServer 应该是本地服务器,与 Internet 无关。我可以从客户端连接到 FTPServer(我得到 230 作为回复代码),但我似乎无能为力。我无法存储或检索任何文件。
我几乎阅读了与此问题相关的所有问题,但提出其他问题的人能够发送简单的文件,但在发送 pdf 等文件时遇到了麻烦。我只需要发送或检索文本文件。
有什么建议么?
FTPClient client = new FTPClient();
String host = "mypc";
String Name = "user";
String Pass = "12345";
client.connect(host);
client.login(Name,Pass);
System.out.println("Reply Code: " +client.getReplyCode());
File file = new File("C:\\.....myfile..txt");
FileInputStream in = new FileInputStream("C:\\.....myfile..txt");
boolean isStored = client.storeFile("uploadedfile.txt", in);
in.close();
client.logout();
System.out.println("isStored: " +isStored);
我没有输入真实的路径名。它返回false,没有异常等。这可能是因为它们在同一台机器上?
编辑:原来我需要写权限才能将文件发送到 ftpserver。默认情况下,它不授予用户写入权限。如何使用 Apache 的 ftpserver 库授予用户写入权限?