530登录或密码不正确

时间:2017-04-11 06:59:20

标签: java ftp-client

这是我在ftp位置上传excel文件的java代码。

 private FTPClient ftp = null;
    @Value("${excelfile.location}")
    private String excelFileLocation;
    @Override
    public void uploadExcelToFTP() throws Exception {
        String host = "";
        String user = "";
        String pass = "";
        String hostDir = "";
        String localFileFullName = excelFileLocation+"errorSongs-"+dateToString(new Date())+".xlsx";
        String fileName = "errorSongs";
        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, pass);
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        ftp.enterLocalPassiveMode();

        File file = new File(localFileFullName);
        if (file.exists()) {
            try (InputStream input = new FileInputStream(file)) {
                this.ftp.storeFile(hostDir + fileName, input);
            }
        }
        /*else{
            throw new ExcelFileNotFoundException("File does not exist on location");
        }*/
        if (this.ftp.isConnected()) {
            try {
                this.ftp.logout();
                this.ftp.disconnect();
            } catch (IOException exception) {
                // do nothing as file is already saved to server
            }
        }

但我收到的错误是:

Command: USER my userid 
Reply: 331 Password required for userid 
Command: PASS **** 
Reply: 530 Login or password incorrect! 

但是当我尝试使用相同的凭据连接FileZilla时,它已成功连接。

感谢。

1 个答案:

答案 0 :(得分:0)

String host = "";
String user = "";
String pass = "";
...
ftp.connect(host);
ftp.login(user, pass)

您正在连接具有空凭据的空主机。您应该为所需的FTP服务器传递有效的主机和凭据