GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Help Please!!! I need an ftp program that will only upload certain file types (https://gfy.com/showthread.php?t=791394)

Snake Doctor 12-11-2007 05:05 PM

Help Please!!! I need an ftp program that will only upload certain file types
 
I replaced link codes on literally thousands of pages and I want to upload them to my server and overwrite the old ones.
The problem is they are in folders that also have alot of images and videos and the program I'm currently using only allows me to either overwrite all or skip all. I need one that will allow me to set the parameters to overwrite html files and skip all the others.

Nails 12-11-2007 05:11 PM

winscp it will let you use wildcards and such to exclude certain file types.

SmokeyTheBear 12-11-2007 05:14 PM

i have a php script that will do that..

i'll take a look and see if i can find it..

you gotta be very carefull though it can really mess things up if you are not carefull

SmokeyTheBear 12-11-2007 05:53 PM

gfy usually fucks up the code but here goes..

p.s. before using this , test it out on a test folder to get used to how it works first .

save the following as

doit.php

make changes as needed

Code:

<?php

require_once('fandr.php');
//folder to search and all subdirs
$path = "folder";
// logfile
$logFile = "/result.txt";
// find this
$find = "test";
//replace with this
$replace = "nast2code";


$obj = new TextSearch();

// extensions to search
$obj->setExtensions(array('html','txt'));
$obj->addExtension('htm');
$obj->setSearchKey("$find");
$obj->setReplacementKey("$replace");
$obj->startSearching($path);
$obj->showLog();
$obj->writeLogToFile($logFile);

?>

save the following as fandr.php

no editing needed
Code:

<?php

class TextSearch
{       
        var $extensions        = array();
        var $searchKey          = '';       
        var $replacementKey    = '';
        var $caseSensitive      = 0;
        var $findAllExts        = 1;
        var $isReplacingEnabled = 0;
        var $logString          = '';
        var $errorText          = '';
        var $totalFound        = 0; //total matches
       
 

  function setExtensions($extensions = array())
  {
      $this->extensions = $extensions;
     
      if(sizeof($this->extensions))       
      {
        $this->findAllExts = 0; //not all extensions
      }
  }//End of Method

 
  function addExtension($extension)
  {
     
      array_push($this->extensions, $extension);     
      $this->findAllExts = 0; //not all extensions
     
  }//End of function

 
 
  function setSearchKey($searchKey, $caseSensitive = 0)
  {
      $this->searchKey = $searchKey;
     
      if($caseSensitivity)
      {
        $this->caseSensitive        = 1;
      }
  }//End of function
 
  function setReplacementKey($replacementKey)
  {
 
      $this->replacementKey    = $replacementKey;
      $this->isReplacingEnabled = 1; 
 
  }//End of function
 

  function startSearching($path)
  {
      $this->findDirFiles($path);     
  }//EO Method
 
 
  function findDirFiles($path)
  {
      $dir = opendir ($path);
     
      while ($file = readdir ($dir))
      {
        if (($file == ".") or ($file == ".."))
        {
            continue;
        }               
                           
                    if (filetype ("$path/$file") == "dir")
                    {                           
            $this->findDirFiles("$path/$file"); //recursive traversing here
        }                       
                                elseif($this->matchedExtension($file)) //checks extension if we need to search this file
                                {                                         
          if(filesize("$path/$file"))
          {
              $this->searchFileData("$path/$file"); //search file data                 
          } 
        }                       
      } //End of while
     
      closedir($dir);
       
  }//EO Method


  function findExtension($file)
  {
          return array_pop(explode(".",$file));
  }//End of function
 
 
  function matchedExtension($file)
  { 
      if($this->findAllExts) //checks if all extensions are to be searched
      {
        return true;       
      }     
      elseif(sizeof(array_keys($this->extensions, $this->findExtension($file)))==1)
      {
        return true;       
      }
     
      return false;               
 
  }//EO Method
 

  function searchFileData($file)
  {
      $searchKey  = preg_quote($this->searchKey);
     
      if($this->caseSensitive)
      {
        $pattern    = "/$searchKey/U";
      }
      else
      {
              $pattern    = "/$searchKey/Ui";
      }
     
      $subject      = file_get_contents($file);
           
      $found = 0;
           
      $found = preg_match_all($pattern, $subject, $matches, PREG_PATTERN_ORDER);                 
     
      $this->totalFound +=$found;
                 
      if($found)
      {
              $foundStr = "Found in $found places";
        $this->appendToLog($file, $foundStr);
      }
     
     
      if($this->isReplacingEnabled && $this->replacementKey && $found)
      {         

// $this->replacementKey = "$replace";
        $outputStr = preg_replace($pattern, $this->replacementKey, $subject);                                   
        $foundStr = "Found in $found places";
        $this->writeToFile($file, $outputStr);
        $this->appendToLog($file, $foundStr, $this->replacementKey);
       
      }
      elseif($this->isReplacingEnabled && $this->replacementKey == '')
      {
        $this->errorText .= "Replacement Text is not defined\n";
        $this->appendToLog($file, "Replacement Text is not defined", $this->replacementKey);
      }
      elseif(!found)
      {
        $this->appendToLog($file, "No matching Found", $this->replacementKey);
      }
     
  }//EO Method
 

  function writeToFile($file, $data)
  {         
      if(is_writable($file))
      {
        $fp = fopen($file, "w");
        fwrite($fp, $data);
        fclose($fp);       
      }
      else
      {
        $this->errorText .= "Can not replace text. File $file is not writable. \nPlease make it writable\n";       
      }
     
  }//EO Method

 
  function appendToLog($file, $matchStr, $replacementKey = null)
  {
            if($this->logString == '')
            {
                $this->logString = " --- Searching for '".$this->searchKey."' --- \n";
            }
     
      if($replacementKey == null)
      {
        $this->logString .= "Searching File $file : " . $matchStr."\n";             
      }
      else
      {
        $this->logString .= "Searching File $file : " . $matchStr.". Replaced by '$replacementKey'\n";             
      }
     
  }//EO Method
 
 
  function showLog()
  {
      $this->dBug("------ Total ".$this->totalFound." Matches Found -----");
      $this->dBug(nl2br($this->logString));             
     
      if($this->errorText!='')
      {
              $this->dBug("------Error-----");
        $this->dBug(nl2br($this->errorText));                   
      }
  }//EO Method
 

  function writeLogToFile($file)
  {     
      $fp = fopen($file, "wb") OR die("Can not open file <b>$file</b>");           
      fwrite($fp, $this->logString);
      fwrite($fp, "\n------ Total ".$this->totalFound." Matches Found -----\n");
      if($this->errorText!='')
      {
        fwrite($fp, "\n------Error-----\n");   
        fwrite($fp, $this->errorText);
      }
     
      fclose($fp);     
  }//EO Method
 

  function dBug($dump)
  {
      echo "<pre>";
      print_r($dump);
      echo "</pre>";       
  }//EO Method
 
} //End of class

?>

step #3 make a file called result.txt place it in the dir with the other 2 files and chmod it to be writeable *optional



this will search all files of the extension you specify in doit.php and find and replace text..

some things to be carefull of..

if you have lots of files make sure your php doesnt cutoff scripts at 30 seconds ( default )

this will replace everything in the dir you specify AND all subdirectories

if you have a question , ask first

Snake Doctor 12-11-2007 07:04 PM

Quote:

Originally Posted by SmokeyTheBear (Post 13501757)
gfy usually fucks up the code but here goes..

p.s. before using this , test it out on a test folder to get used to how it works first .

save the following as

doit.php

make changes as needed

Code:

<?php

require_once('fandr.php');
//folder to search and all subdirs
$path = "folder";
// logfile
$logFile = "/result.txt";
// find this
$find = "test";
//replace with this
$replace = "nast2code";


$obj = new TextSearch();

// extensions to search
$obj->setExtensions(array('html','txt'));
$obj->addExtension('htm');
$obj->setSearchKey("$find");
$obj->setReplacementKey("$replace");
$obj->startSearching($path);
$obj->showLog();
$obj->writeLogToFile($logFile);

?>

save the following as fandr.php

no editing needed
Code:

<?php

class TextSearch
{       
        var $extensions        = array();
        var $searchKey          = '';       
        var $replacementKey    = '';
        var $caseSensitive      = 0;
        var $findAllExts        = 1;
        var $isReplacingEnabled = 0;
        var $logString          = '';
        var $errorText          = '';
        var $totalFound        = 0; //total matches
       
 

  function setExtensions($extensions = array())
  {
      $this->extensions = $extensions;
     
      if(sizeof($this->extensions))       
      {
        $this->findAllExts = 0; //not all extensions
      }
  }//End of Method

 
  function addExtension($extension)
  {
     
      array_push($this->extensions, $extension);     
      $this->findAllExts = 0; //not all extensions
     
  }//End of function

 
 
  function setSearchKey($searchKey, $caseSensitive = 0)
  {
      $this->searchKey = $searchKey;
     
      if($caseSensitivity)
      {
        $this->caseSensitive        = 1;
      }
  }//End of function
 
  function setReplacementKey($replacementKey)
  {
 
      $this->replacementKey    = $replacementKey;
      $this->isReplacingEnabled = 1; 
 
  }//End of function
 

  function startSearching($path)
  {
      $this->findDirFiles($path);     
  }//EO Method
 
 
  function findDirFiles($path)
  {
      $dir = opendir ($path);
     
      while ($file = readdir ($dir))
      {
        if (($file == ".") or ($file == ".."))
        {
            continue;
        }               
                           
                    if (filetype ("$path/$file") == "dir")
                    {                           
            $this->findDirFiles("$path/$file"); //recursive traversing here
        }                       
                                elseif($this->matchedExtension($file)) //checks extension if we need to search this file
                                {                                         
          if(filesize("$path/$file"))
          {
              $this->searchFileData("$path/$file"); //search file data                 
          } 
        }                       
      } //End of while
     
      closedir($dir);
       
  }//EO Method


  function findExtension($file)
  {
          return array_pop(explode(".",$file));
  }//End of function
 
 
  function matchedExtension($file)
  { 
      if($this->findAllExts) //checks if all extensions are to be searched
      {
        return true;       
      }     
      elseif(sizeof(array_keys($this->extensions, $this->findExtension($file)))==1)
      {
        return true;       
      }
     
      return false;               
 
  }//EO Method
 

  function searchFileData($file)
  {
      $searchKey  = preg_quote($this->searchKey);
     
      if($this->caseSensitive)
      {
        $pattern    = "/$searchKey/U";
      }
      else
      {
              $pattern    = "/$searchKey/Ui";
      }
     
      $subject      = file_get_contents($file);
           
      $found = 0;
           
      $found = preg_match_all($pattern, $subject, $matches, PREG_PATTERN_ORDER);                 
     
      $this->totalFound +=$found;
                 
      if($found)
      {
              $foundStr = "Found in $found places";
        $this->appendToLog($file, $foundStr);
      }
     
     
      if($this->isReplacingEnabled && $this->replacementKey && $found)
      {         

// $this->replacementKey = "$replace";
        $outputStr = preg_replace($pattern, $this->replacementKey, $subject);                                   
        $foundStr = "Found in $found places";
        $this->writeToFile($file, $outputStr);
        $this->appendToLog($file, $foundStr, $this->replacementKey);
       
      }
      elseif($this->isReplacingEnabled && $this->replacementKey == '')
      {
        $this->errorText .= "Replacement Text is not defined\n";
        $this->appendToLog($file, "Replacement Text is not defined", $this->replacementKey);
      }
      elseif(!found)
      {
        $this->appendToLog($file, "No matching Found", $this->replacementKey);
      }
     
  }//EO Method
 

  function writeToFile($file, $data)
  {         
      if(is_writable($file))
      {
        $fp = fopen($file, "w");
        fwrite($fp, $data);
        fclose($fp);       
      }
      else
      {
        $this->errorText .= "Can not replace text. File $file is not writable. \nPlease make it writable\n";       
      }
     
  }//EO Method

 
  function appendToLog($file, $matchStr, $replacementKey = null)
  {
            if($this->logString == '')
            {
                $this->logString = " --- Searching for '".$this->searchKey."' --- \n";
            }
     
      if($replacementKey == null)
      {
        $this->logString .= "Searching File $file : " . $matchStr."\n";             
      }
      else
      {
        $this->logString .= "Searching File $file : " . $matchStr.". Replaced by '$replacementKey'\n";             
      }
     
  }//EO Method
 
 
  function showLog()
  {
      $this->dBug("------ Total ".$this->totalFound." Matches Found -----");
      $this->dBug(nl2br($this->logString));             
     
      if($this->errorText!='')
      {
              $this->dBug("------Error-----");
        $this->dBug(nl2br($this->errorText));                   
      }
  }//EO Method
 

  function writeLogToFile($file)
  {     
      $fp = fopen($file, "wb") OR die("Can not open file <b>$file</b>");           
      fwrite($fp, $this->logString);
      fwrite($fp, "\n------ Total ".$this->totalFound." Matches Found -----\n");
      if($this->errorText!='')
      {
        fwrite($fp, "\n------Error-----\n");   
        fwrite($fp, $this->errorText);
      }
     
      fclose($fp);     
  }//EO Method
 

  function dBug($dump)
  {
      echo "<pre>";
      print_r($dump);
      echo "</pre>";       
  }//EO Method
 
} //End of class

?>

step #3 make a file called result.txt place it in the dir with the other 2 files and chmod it to be writeable *optional



this will search all files of the extension you specify in doit.php and find and replace text..

some things to be carefull of..

if you have lots of files make sure your php doesnt cutoff scripts at 30 seconds ( default )

this will replace everything in the dir you specify AND all subdirectories

if you have a question , ask first

I appreciate the effort you put into doing all of that, but I don't want a server side search and replace. I just want an FTP program that will only upload the file types I tell it to and skip the rest.

djscrib 12-11-2007 09:16 PM

If it's just one big folder, why can't you just view all files, sort by extension, then shift-select all the .html files (since they'll be grouped) and click the upload button.

Snake Doctor 12-11-2007 10:20 PM

Quote:

Originally Posted by djscrib (Post 13502339)
If it's just one big folder, why can't you just view all files, sort by extension, then shift-select all the .html files (since they'll be grouped) and click the upload button.

I would if it was one big folder.

Everything is in a subfolder.
I structured things that way to keep them organized....go figure


All times are GMT -7. The time now is 08:58 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123