ftp_rename overwrite

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    ftp_rename overwrite

    ftp_rename seems to be the only way to move files from one remote folder to another.
    If the file already exists in the 'to' folder, ftp_rename returns false.
    Is there a way of over-riding this and rename(move) the file anyway?
  • erayfield
    New Member
    • Jan 2010
    • 4

    #2
    what is the code for the ftp?

    Comment

    • erayfield
      New Member
      • Jan 2010
      • 4

      #3

      Supports stat() No As of PHP 5.0.0: filesize(), filetype(), file_exists(), is_file(), and is_dir() elements only. As of PHP 5.1.0: filemtime().

      so, see if the file is there, if it is then you can rename it
      PHP4 PHP5
      Supports rename() No Yes
      Not sure what you can do if you have 4, but there is probably a work around someplace - PHP 5 works great for this - also verify if passive or active setting, because that can cause problems

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        Hello erayfield, I'm afraid you have lost me.
        The code in question is actually a class method
        Code:
        //ftp_rename returns false if the file already exists. 
        //Doesn't seem to be an overwrite
        public function movefile($filename,$from='',$to='')
        {
        	print "<br>Move file - from $from.$filename to $to.$filename";
        	if(ftp_rename($this->resource,$from.$filename,$to.$filename))
        		return true;
        	echo "ftp_rename failed moving $filename from $from to $to";
        	return false;
        	}
        The scenario is I am downloading order files for processing.
        If the order file has a problem I move it to a 'Problems' folder, where a third party can amend the file.
        But they don't always remove the file from Problems and amend the file correctly, so at the next download ftp_rename() tries to place the file in Problems again, but fails

        Comment

        Working...