FTP using Apache commons not working - Error: 550 Dataset not found (FTPid that i am using is getting appended to filename)

FTP using Apache commons not working - Error: 550 Dataset not found (FTPid that i am using is getting appended to filename)

我正在尝试 ftp 文件从 Linux VM 到 AS400 服务器。我能够以被动模式登录到服务器,但是当尝试使用 STOR 命令上传文件时出现以下错误:

STOR XX.YY600040.XXXZZZXXX        
**550 Dataset not found, DSN=FTPID.XX.YY600040.XXXZZZXXX**

不确定为什么我使用的 ftpid 会作为文件名的前缀。有什么办法可以避免吗? 下面是我正在使用的示例代码:

private static String sendFTPFile(String fileName) throws Exception {
        StringBuffer ftpMessage = new StringBuffer();
        if (SHOW_DEBUG) ftpMessage.append("<ul>");
        FTPClient ftp = null;
        
        try {
            String server = "****";
            String username = "****";
            String password = "XXXXX";
            String hostDir = "";
            String localFileName = fileName;
            String localFilePath = "***/**/*";
            
            boolean binaryTransfer = false, error = false;
            
            FTPClient ftp = new FTPClient();
            ftp.addProtocolCommandListener(new PrintCommandListener(
                                               new PrintWriter(System.out)));
          
            int reply;
                ftp.connect(server)
                
                // After connection attempt, you should check the reply code to verify
                // success.
                reply = ftp.getReplyCode();

                if (!FTPReply.isPositiveCompletion(reply))
                {
                    ftp.disconnect();
                    error = true;
                }
            
          if(!error) {
                
                    if (!ftp.login(username, password))
                    {
                        ftp.logout();
                        error = true;
                    }
             if(!error) {
                    if (binaryTransfer)
                        ftp.setFileType(FTP.BINARY_FILE_TYPE);

                    // Use passive mode as default 
                    ftp.enterLocalPassiveMode();
                    InputStream input;
                    input = new FileInputStream(localFilePath+localFileName);
                    boolean ftpSuccess = ftp.storeFile(hostDir+localFileName, input);
                    input.close();
                       
                    if (!ftpSuccess) {
                        throw new Exception("File ftp error");
                    }else {
                        if (SHOW_DEBUG) ftpMessage.append("<li>isFtpSuccess()...success").append("</li>");
                    }
                    
                    ftp.logout();
                    if (SHOW_DEBUG) ftpMessage.append("<li>ftp.logout()...success").append("</li>");
                    
             }
        }    
                 
        }
        catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("Exception occur while transfering file using ftp"+ ex.toString());
            throw new Exception(ftpMessage.toString(), ex);
        }
        finally {
            if (ftp!=null && ftp.isConnected())
            {
                try
                {
                    ftp.disconnect();
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                    System.out.println("Exception occur while transfering file using ftp"+ e.toString());
                    throw new Exception(ftpMessage.toString(), e);
                }
            }
        
            if (SHOW_DEBUG) ftpMessage.append("</ul>");
        }
        return ftpMessage.toString();
    }

我对 ftp 从 linux 到 as400 进行了更多调试。在登录到 ftp 服务器后执行 pwd 时,其给出的消息为:
ftp>密码
257 “'FTPID.'”是当前前缀

并考虑如何删除该前缀,所以我 运行 下面的命令得到了没有定义前缀的输出:

ftp> cd ..
200 "" 没有定义前缀

之后,当我使用 put 命令上传文件时,它已成功上传。所以我研究了如何使用我正在使用的 Apache commons.net api 返回一个目录,并找到了 CDUP 方法。

当我运行上传文件前的FTPClient.cdup()方法。我也能够从 java 代码成功 FTP 文件。

ftp.cdup();
input = new FileInputStream(localFilePath+localFileName);
boolean ftpSuccess = ftp.storeFile(hostDir+localFileName, input);