title: FTP using Apache commons not working - Error: 550 Dataset not found (FTPid that i am using is getting appended to filename)
body: <p>I am trying to ftp the file from Linux VM to an AS400 server. I was able to login to server in passive mode but when trying to use the STOR command to upload the file getting below error:</p>
  <pre><code>STOR XX.YY600040.XXXZZZXXX        
  **550 Dataset not found, DSN=FTPID.XX.YY600040.XXXZZZXXX**
  </code></pre>
  <p>Not sure why the ftpid that i am using is getting prefixed to the filename. Is there any way to avoid it?
  Below is the sample code that i am using:</p>
  <pre><code>private static String sendFTPFile(String fileName) throws Exception {
          StringBuffer ftpMessage = new StringBuffer();
          if (SHOW_DEBUG) ftpMessage.append(&quot;&lt;ul&gt;&quot;);
          FTPClient ftp = null;
          
          try {
              String server = &quot;****&quot;;
              String username = &quot;****&quot;;
              String password = &quot;XXXXX&quot;;
              String hostDir = &quot;&quot;;
              String localFileName = fileName;
              String localFilePath = &quot;***/**/*&quot;;
              
              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(&quot;File ftp error&quot;);
                      }else {
                          if (SHOW_DEBUG) ftpMessage.append(&quot;&lt;li&gt;isFtpSuccess()...success&quot;).append(&quot;&lt;/li&gt;&quot;);
                      }
                      
                      ftp.logout();
                      if (SHOW_DEBUG) ftpMessage.append(&quot;&lt;li&gt;ftp.logout()...success&quot;).append(&quot;&lt;/li&gt;&quot;);
                      
               }
          }    
                   
          }
          catch (Exception ex) {
              ex.printStackTrace();
              System.out.println(&quot;Exception occur while transfering file using ftp&quot;+ ex.toString());
              throw new Exception(ftpMessage.toString(), ex);
          }
          finally {
              if (ftp!=null &amp;&amp; ftp.isConnected())
              {
                  try
                  {
                      ftp.disconnect();
                  }
                  catch (Exception e)
                  {
                      e.printStackTrace();
                      System.out.println(&quot;Exception occur while transfering file using ftp&quot;+ e.toString());
                      throw new Exception(ftpMessage.toString(), e);
                  }
              }
          
              if (SHOW_DEBUG) ftpMessage.append(&quot;&lt;/ul&gt;&quot;);
          }
          return ftpMessage.toString();
      }
  </code></pre>