FTP file upload failure Java

Refresh

November 2018

Views

2k time

7

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?

1 answers

5

Проблема решена: Это как дать разрешение пользователя на запись. Я добавил этот фрагмент кода на стороне сервера, и она работала.

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

Authority auth = new WritePermission();

auths.add(auth);

user.setAuthorities(auths);

Там же термин Authorityнаписано в этом символе -> < >после того, как Listи ArrayListв первой строке. Сайт не видит слов в <>символе.