[gollem] FTP VFS functions (was Other Gollem issues)
    Jeff Graves 
    jeff at image-src.com
       
    Fri Feb 21 17:10:29 PST 2003
    
    
  
Here's my attempt at implementing so missing FTP functions in the
horde VFS. I re-worked what was already in place for the sql_file
backend. I've never written php code before but they seem to work on
my installation. Somebody with some PHP experience should take a look
over them, make necessary changes, and commit them after testing:
    /**
     * 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;
    }
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
-----Original Message-----
From: gollem-bounces at lists.horde.org
[mailto:gollem-bounces at lists.horde.org]On Behalf Of Chuck Hagenbuch
Sent: Thursday, February 20, 2003 2:52 PM
To: gollem at lists.horde.org
Subject: RE: [gollem] Other Gollem issues
Please keep threads on the list.
Quoting Jeff Graves <jeff at image-src.com>:
> Where would I find these functions (for other backends)? I'll make a
pass
> at working on them.
horde/lib/VFS/*.php
-chuck
--
Charles Hagenbuch, <chuck at horde.org>
must ... find ... acorns ... *thud*
--
Gollem mailing list
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: gollem-unsubscribe at lists.horde.org
    
    
More information about the gollem
mailing list