title: Warning: ftp_rename(): User logged in (rename files with foreach loop)
body: <p>I have a text file with bunch of file's path in my ftp server, I wanna rename all of them with foreach loop but PHP warns "User Logged in" and unable to rename them:</p>
  
  <pre><code>$links = file('filepath.txt');
  
  foreach($links as $link){
      // connect and login to FTP server
      $ftp_server = "myftpserver";
      $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
      $login = ftp_login($ftp_conn, $ftp_user_name, $ftp_user_pass);
  
      $old_file = $link;
      $new_file = str_replace("badword", "goodword",$old_file);
  
      // try to rename $old_file to $new_file
      if (ftp_rename($ftp_conn, $old_file, $new_file))
        {
        echo "Renamed $old_file to $new_file";
        echo '&lt;hr&gt;';
        }
      else
        {
        echo "Problem renaming $old_file to $new_file";
        }
  
      // close connection
      ftp_close($ftp_conn);
  }
  </code></pre>
  
  <blockquote>
    <p>Warning: ftp_rename(): User logged in</p>
  </blockquote>