FTP file upload failure Java


November 2018


2k time


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";

        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);
        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


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

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

Authority auth = new WritePermission();



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