Java FTP文件上传失败

发布于 2024-11-08 22:02:43 字数 984 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

年少掌心 2024-11-15 22:02:43

问题解决:
这是授予用户写入权限的方法。我将此片段添加到服务器端并且它起作用了。

List<Authority> auths = new ArrayList<Authority>();

Authority auth = new WritePermission();

auths.add(auth);

user.setAuthorities(auths);

这个符号中写有术语Authority -> <代码>< > 第一行中的 ListArrayList 之后。网站看不到 <> 符号中的文字。

Problem Solved:
This is how to give a user write permission. I added this snippet to server side and it worked.

List<Authority> auths = new ArrayList<Authority>();

Authority auth = new WritePermission();

auths.add(auth);

user.setAuthorities(auths);

There's term Authority written in this symbol -> < > after List and ArrayList in the first line. Site doesn't see words in <> symbol.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文