Java FTP文件上传失败
我在 Java 项目中使用 Apache 的 FTPClient 和 FTPServer 库。服务器和客户端在同一台机器上。
我的FTP服务器应该是本地服务器,与互联网无关。我可以从客户端连接到 FTP 服务器(我得到 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 库授予用户写权限?
I use Apache's FTPClient and FTPServer libraries in my Java project. Server and client are on the same machine.
My FTPServer is supposed to be a local server,nothing related to the Internet. I can connect to the FTPServer from the client(I get 230 as reply code) but i cant seem to do anything. I cant store or retrieve any files.
I read almost every question related to this matter but people who asked other questions were be able to send simple files and had trouble with sending files like pdf etc. I just need to send or retrieve text files.
Any suggestions?
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);
I didnt put the real path names. It returns false,no exceptions etc. This might be because of they're on the same machine?
Edit: Turned out i needed write permission to send a file to ftpserver. By default, it doesnt give users write permission. How can i give users write permission using Apache's ftpserver library?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题解决:
这是授予用户写入权限的方法。我将此片段添加到服务器端并且它起作用了。
这个符号中写有术语
Authority
-> <代码>< > 第一行中的List
和ArrayList
之后。网站看不到<>
符号中的文字。Problem Solved:
This is how to give a user write permission. I added this snippet to server side and it worked.
There's term
Authority
written in this symbol ->< >
afterList
andArrayList
in the first line. Site doesn't see words in<>
symbol.