Skip to content
Advertisement

Java FTP 550 error

I’m getting this error (550 the filename, directory name, or volume label syntax is incorrect. ) I think the url is correct (obviously not though). Any thoughts?

Here is the url:

STOR /images/report/6F81CB22-3D04-4BA3-AC3F-3D34663449E0**9.png

Here is the invocation method:

private void uploadImageToFtp(String location, String imageName) throws Exception{

        File imageFile = new File(location);

        System.out.println("Start");
        FTPUploader ftpUploader = new FTPUploader("ftp.xxx.com", "user", "password");

        ftpUploader.uploadFile(imageFile, imageName, "/images/report/");

        imageFile.delete();
        ftpUploader.disconnect();
        System.out.println("Done");
    }
Here is the

ftp class:

package server;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;

public class FTPUploader {

    FTPClient ftp = null;

    public FTPUploader(String host, String user, String pwd) throws Exception{


        ftp = new FTPClient();
        ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
        int reply;
        ftp.connect(host);
        reply = ftp.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            throw new Exception("Exception in connecting to FTP Server");
        }
        ftp.login(user, pwd);
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        ftp.enterLocalPassiveMode();
    }
    public void uploadFile(File file, String fileName, String hostDir)
            throws Exception {

        try {
            InputStream input = new FileInputStream(file);
            this.ftp.storeFile(hostDir + fileName, input);

        } catch (Exception e) {

            // TODO: handle exception
            e.printStackTrace();
        }

    }

    public void disconnect(){
        if (this.ftp.isConnected()) {
            try {
                this.ftp.logout();
                this.ftp.disconnect();
            } catch (IOException f) {
                // do nothing as file is already saved to server
                f.printStackTrace();
            }
        }
    }
}

Advertisement

Answer

If the FTP server is running Windows, the ‘*’ characters are the problem. Windows file names may not have asterisks.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement