简体   繁体   English

FTP文件上传失败Java

[英]FTP file upload failure Java

I use Apache's FTPClient and FTPServer libraries in my Java project. 我在Java项目中使用Apache的FTPClient和FTPServer库。 Server and client are on the same machine. 服务器和客户端在同一台机器上。

My FTPServer is supposed to be a local server,nothing related to the Internet. 我的FTPServer应该是本地服务器,与Internet无关。 I can connect to the FTPServer from the client(I get 230 as reply code) but i cant seem to do anything. 我可以从客户端连接到FTPServer(我得到230作为回复代码),但我似乎无能为力。 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. 我几乎阅读了与此事有关的每一个问题,但是那些提出其他问题的人能够发送简单的文件,并且无法发送像pdf等文件。我只需要发送或检索文本文件。

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? 它返回false,没有异常等。这可能是因为它们在同一台机器上?

Edit: Turned out i needed write permission to send a file to ftpserver. 编辑:原来我需要写权限才能将文件发送到ftpserver。 By default, it doesnt give users write permission. 默认情况下,它不会授予用户写入权限。 How can i give users write permission using Apache's ftpserver library? 如何使用Apache的ftpserver库为用户提供写入权限?

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. 有一个术语Authority写在这个符号 - > < >在第一行的ListArrayList之后。 Site doesn't see words in <> symbol. 网站在<>符号中看不到单词。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM