【问题标题】:Java FTP 550 errorJava FTP 550 错误
【发布时间】:2013-10-27 02:38:55
【问题描述】:

我收到此错误(550 文件名、目录名或卷标语法不正确。) 我认为网址是正确的(但显然不是)。有什么想法吗?

这里是网址:

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

调用方法如下:

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 类:

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

【问题讨论】:

  • FTP 服务器是否运行 Windows? Windows 文件名may not have asterisks.
  • 就是这样...谢谢
  • 你应该把它作为答案
  • 550 是连接错误的标准。

标签: java ftp


【解决方案1】:

如果 FTP 服务器运行 Windows,则“*”字符是问题所在。 Windows 文件名may not have asterisks

【讨论】:

    【解决方案2】:

    尝试在上传前先更改工作目录 ftp.changeWorkingDirectory(DESTPATH);

    它对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多