I've decided to open a new thread for discussing the problem with uploading a file to a SUB-FOLDER at the FTP Server. So, I'm using Apache Commons library and I can upload my file to the Home Directory of the FTP server. However, if I want to upload it to some sub-folder, then nothing happens (no results, no errors). Please, give me some advices. Thanks!

import org.apache.commons.net.ftp.*;


private saveRemote() {
        FTPClient client = new FTPClient();
        FileInputStream fis = null;

        try {

            // Create an InputStream of the file to be uploaded
            String filename = text4.getText();
            fis = new FileInputStream(pathToFile);

            // Store file to server
            client.storeFile(filename, fis);
        } catch (IOException e) {
        } finally {
            try {
                if (fis != null) {
            } catch (IOException e) {


Recommended Answers

All 9 Replies

Does the sub folder exist? What happens when you try to create a new sub folder?

Yes, sure, the sub-folder exists. In order to save a file let's say in sub-folder Documents, I run the following code (file name is stored in text4):

String filename = "Documents/"+text4.getText();

I haven't tried to create a new folder from Java.

Please, help me to solve this problem.

What operating system are you using and to what operating system are you trying to connect? A while ago I had problems when connecting to a remote system with a different OS. You can try "\\" as well instead of "/".

Well, currently my FTP server is installed on my PC (I'm just debugging my software). In the future, I will connect this FTP server from another PC. So, it means that now OS is the same (Windows 7). However, what you said is very important, because in the future I will probably run my software on another OS. How did you solve this problem?

Also, I've tried "\\" - no result:(

I've included System.out.println in the code to see "filename" and "pathToFile". To define "filename", I run "String filename = "Documents\\" + text4.getText();". But why the file is not saved in Documens sub-folder?

filename: Documents\handnotes.doc
pathToFile: D:\handnotes.doc

"Documents\" + text4.getText();" is actually the string Documents"<text file> - perhaps you want "Documents\\" + text.getText(); ?

Ups, the problem was with my FTP Server. I had to delete "Documents" from the list of shared folders, so that only the root directory is shared (which means that all folders inside this root directory are also shared). And now it works! Thanks!

However, I would like to get the answer on my question regarding different OS. How did you solve it?

I used the "trivial" solution of invoking System.getProperty("os.name") :)

Glad I could help you man, please mark the problem as solved :)

Ok, thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.