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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With