PHP Classes

File: ftp.php

Recommend this page to a friend!
  Classes of David Passey   ZEND_EPS_PUTTY   ftp.php   Download  
File: ftp.php
Role: Example script
Content type: text/plain
Description: Example script & further info
Class: ZEND_EPS_PUTTY
Send files to secure FTP server using Putty
Author: By
Last change: Fix slight spelling error.
Date: 13 years ago
Size: 2,815 bytes
 

Contents

Class file image Download
<?php

/**
 * Example script to show the functionality of ZEND_EPS_PUTTY.
 *
 * You will need the PuTTY application installed on your computer.
 *
 * You will need the Zend Framework installed.
 *
 * You will need an XML config file to pass to the class so FTP settings can be configured. Just supply
 * the necessary path to the file and the root node name. This allows for multiple FTP server configurations
 * in one file.
 *
 * The output files are a log file that contains the FTP batch commands and an XML results file that
 * has all of the results of the batch commands. This file can be parsed for usage within the calling script.
 *
 * The lines below will customize the log and results files, make directories on the remote server,
 * send files, move files, get files, and then delete the directories and any files in them.
 *
 * XML config file settings instructions:
 *
 * <putty_path> = Where you installed the PuTTY application. This can be blank if this path is in your PATH environment.
 * <ftp1> = Some type of parent node. Call it anything you wish and use this name when you create the instance.
 * <host> = The FTP host.
 * <port> = The port to use. Defaults to 22 if left blank.
 * <username> = The user name.
 * <password> = The password.
 * <local_upload_path> = The local path for uploading files from.
 * <local_download_path> = The local path for downloading files to.
 * <remote_path> = The remote path to start the session in. Usually defaults to the FTP home directory or "/".
 * <results_path> = The local path where the results file should be written to.
 * <log_path> = The local path where the log file should be written to.
 */

   
require_once 'lib/class.zend_eps_putty.inc';

   
   
$con = new ZEND_EPS_PUTTY('c:/php/includes/config/ftp_config.xml','ftp1');
   
$con->setLogText('### begin log ###', '### end log ###');
   
$con->renameLogFile('my_log_file.txt',0,1);
   
$con->renameResultsFile('my_results_file.xml');
   
$con->setXMLNodes(array('root'=>'rootNode','batch'=>'batchNode','command'=>'cmdNode','result'=>'resNode'));
   
$con->getRemoteDir();
   
$con->getLocalDir();
   
$con->setRemoteDir();
   
$con->setLocalDir($con->localUploadPath);
   
$con->getRemoteDirList('/');
   
$con->makeRemoteDir('dir1');
   
$con->setRemoteDir('/dir1');
   
$con->setFiles(array('x*.txt'));
   
$con->makeRemoteDir(array('\dir2','/dir3/'));
   
$con->setFiles(array(array('a.txt','a.bak'),array('b.txt','b.bak'),'c.txt','d.txt','e.txt'));
   
$con->moveFiles(array(array('x1.txt','/dir3/x1.bak'),array('x2.txt','/dir2')));
   
$con->setLocalDir($con->localDownloadPath);
   
$con->getFiles(array('/dir2/x2.txt','/dir3/*.bak','/dir1/*.*'));
   
$con->removeFiles(array('/dir1/*.txt'));
   
$con->removeRemoteDir(array('/dir1','/dir2','/dir3'),true);
   
$con->exec();


?>