title: Error while Rename file in ftp folder Java
body: <p>Following is my code to read the file and rename it afterwards. Im using <code>apache commons.net 3.0.1</code>.</p>
  
  <pre><code>client.connect(localhost);
  boolean login = client.login("username", "password");
  if(login){
      System.out.println("login successful");
      boolean chdir = client.changeWorkingDirectory("/home/folder1/child/");
      String url = client.printWorkingDirectory();   // EDIT
      FTPFile[] result = client.listFiles(url, filter);
      if (result != null &amp;&amp; result.length &gt; 0) {
          for (FTPFile aFile : result) {
              try{
                  String filename = aFile.getName();
                  InputStream is= client.retrieveFileStream(filename);
                  br = new BufferedReader(new InputStreamReader(is));
                      while((line = br.readLine()) != null){
                          System.out.println("the line is"+line);
                       }
                  }
                  finally{
                      if(br!=null){
                          try{
                             br.close();
                             String oldFilename =url + "/" +aFile.getName();
                             String newFilename = "PRO"+aFile.getName();
                             boolean rename = client.rename(oldFilename, newFilename);
                              if(rename){
                                      System.out.println("renamed");
                              }   
                             else{
                                      System.out.println("Error in renaming");
                                  }
  
                            }
  </code></pre>
  
  <p>The file deosn't get renamed and the program prints </p>
  
  <blockquote>
    <p>error in renaming files (cz boolean rename = false).</p>
  </blockquote>
  
  <p>I have refereed to different examples. But all seems to show the same problem.
  The file is picked after filter and read without any issues.</p>
  
  <p>If anyone could point to what I'm doing wrong here, that'd be very helpful.</p>
  
  <p>Here, the <code>url</code> is <code>String url = client.printWorkingDirectory();</code></p>
  
  <p>I have tried with both relative path and absolute path. And giving full path only to the <code>oldFilename</code> and just the filname to the <code>newFilename</code>. Both did not work.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Before changing the directory, the url will be <code>/</code> which is root.
  After changing the directory, the url will be <code>/home/folder1/child/</code>. This is the where the files exists.</p>