[horde] RE: FTP VFS functions (was Other Gollem issues)

Jeff Graves jeff at image-src.com
Fri Feb 21 14:13:45 PST 2003


Cleaner copy.

Jeff Graves
Customer Support Engineer
Image Source, Inc.
10 Mill Street
Bellingham, MA 02019

jeff at image-src.com - Email
508.966.5200 X31 - Phone
508.966.5170 - Fax
-------------- next part --------------
    /**
     * Returns a sorted folder list of the current directory.
     *
     * @param mixed   $filter   (optional) hash of items to filter based on folderlist.
     *
     * @return mixed  Folder list on success or a PEAR_Error object on failure.
     */
    
    function listFolders($filter = null)
    {
        $conn = $this->_connect();
        if (is_a($conn, 'PEAR_Error')) {
            return $conn;
        }

        $folders = array();
	  $folder = array();	

	  $folderList = $this->listFolder('',null,true,true);
        
	  foreach ($folderList as $files) {
            $folder['val'] = $files['name'];	
		$folder['abbrev'] = $folder['val'];
		$folder['label'] = $folder['val'];

            $folders[$folder['val']] = $folder;
        }
	
	  ksort($folders);
	  return $folders;
    }

    /**
     * Copies a file through the backend.
     *
     * @param string  $path        The path to store the file in.
     * @param string  $name        The filename to use.
     * @param string  $dest        The destination of the file.
     *
     * @return mixed  True on success or a PEAR_Error object on failure.
     */

    function copy($path, $name, $dest)
    {
        $conn = $this->_connect();
        if (is_a($conn, 'PEAR_Error')) {
            return $conn;
        }

        $fileCheck = $this->listFolder($dest, null, false);
        foreach ($fileCheck as $file) {
            if ($file['name'] == $name) {
                return PEAR::raiseError('File already exists');
            }
        }

        if (is_dir($this->_getPath($path, $name))) {
            //return $this->_recursiveCopy($path, $name, $dest);
            return PEAR::raiseError('Directory copy not supported');
        }
 
        $tmpFile = Horde::getTempFile('vfs', false);
        if (!(@ftp_get($this->_stream, $tmpFile, $this->_getPath('/' . $path, $name), FTP_BINARY))) {
            return PEAR::raiseError('Retrieve file failed: ' . $this->_getPath('/' . $path, $name));
        }
 
        if (!(@ftp_put($this->_stream, $this->_getPath('/' . $dest, $name), $tmpFile, FTP_BINARY))) {
	      return PEAR::raiseError('Copy file failed: ' . $this->_getPath('/' . $dest, $name));
	  }

        return true;
   }


    /**
     * Moves a file through the backend.
     *
     * @param string  $path        The path to store the file in.
     * @param string  $name        The filename to use.
     * @param string  $dest        The destination of the file.
     *
     * @return mixed  True on success or a PEAR_Error object on failure.
     */

    function move($path, $name, $dest)
    {
        $conn = $this->_connect();
        if (is_a($conn, 'PEAR_Error')) {
            return $conn;
        }

        if (!($this->copy($path, $name, $dest))) {
	      return PEAR::raiseError('Copy file failed');
        }
	
	  if (!(@ftp_delete($this->_stream, $this->_getPath('/' . $path, $name)))) {
	      return PEAR::raiseError('Delete file failed');
	  }
	
        return true;
    }


More information about the horde mailing list