Is this possible via FTP?

Discussion in 'Site & Server Administration' started by efficients, Nov 14, 2008.

  1. #1
    Hi guys,

    I got certain files uploaded onto a server and I wish to batch rename them with a suffix,

    For example, say I got 150 PDFs on the servers with names like
    I want each one of them to have a suffix like
    Is this possible?

    Also, is it possible to accrue a file list out of an FTP program. As in the above case can I have a text file with the names
    on seperate lines.

    Please let me know!
     
    efficients, Nov 14, 2008 IP
  2. jezzz

    jezzz Notable Member

    Messages:
    4,884
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    200
    #2
    Yes! it can be possible you can edit those file names one by one using any FTP Software! like FileZilla
     
    jezzz, Nov 14, 2008 IP
  3. efficients

    efficients Peon

    Messages:
    132
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ugghhh... doesn't even a small kid know that?

    I questioned on batch renaming and not individual renaming. Come on man!
     
    efficients, Nov 14, 2008 IP
  4. Nicodemus

    Nicodemus Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I have a perl script that i wrote for my personal use for this very thing, it basically does a dir command on your directory, then changes the file name to whatever you want. if you know perl at all you could very easily mod it for your needs.
     
    Nicodemus, Nov 14, 2008 IP
  5. efficients

    efficients Peon

    Messages:
    132
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Alright folks, I figured out a way to do the following....

    Here's the PHP for mass renaming files in a folder,
    <?php
    /****************************************************************************
    * DO NOT REMOVE *
    
    Project: PHPWeby file renamer version 1.0
    Url: http://phpweby.com/
    Copyright: (C) 2008 Blagoj Janevski - bl@blagoj.com
    Project Manager: Blagoj Janevski
    
    More info, sample code and code implementation can be found here:
    http://phpweby.com/software/filerenamer
    
    For help, feature requests, comments, feedback, discussion ... please join our
    Webmaster forums - http://forums.phpweby.com
    
    Visit http://phpweby.com for the latest PHP tutorials, articles, etc.
    
    ///PLEASE BACKUP YOUR FILES BEFORE EXECUTING THIS SCRIPT///
    
    *****************************************************************************
    *  If you like this software please link to us!                             *
    *  Use this code:						                                    *
    *  <a href="http://phpweby.com/software/filerenamer">PHP file renamer</a>   *
    *****************************************************************************
    
    License:
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    
    *********************************************************/
    
    
    ///PLEASE BACKUP YOUR FILES BEFORE EXECUTING THIS SCRIPT///
    
    // the directory
    // './' - is the current directory
    // '../' - is the parent directory
    // case sensitive
    // e.x.: /home/user or c:\files
    $dir='./';
    
    // 1 - uppercase all files
    // 2 - lowercase all files
    // 3 - do not uppercase or lowercase
    $up=3;
    
    //rename files that have $w in their filename
    //case sensitive
    //set to '' if you want to rename all files
    $w='';
    
    //do not rename files having $n in their filename
    $n='';
    
    //add prefix to files
    $prefix='';
    
    //add postfix
    $postfix='';
    
    //replace
    $replace='';
    $replace_with='';
    
    //true - traverse subdirectories
    //false - do not traverse subdirectories
    $tr=false;
    
    
    
    ////// do NOT change anything below this /////////
    set_time_limit(120);
    $files=array();
    error_reporting(E_ERROR | E_PARSE);
    function prep($f,$dir)
    {
    	global $up,$prefix,$postfix,$w,$replace_with,$replace,$n,$files;
    	if(strpos($f,$n)!==false)
    	return $f;
    	$f=str_replace($replace,$replace_with,$f);
    	if($up==1)
    	$f=strtoupper($f);
    	elseif($up==2)
    	$f=strtolower($f);
    	$f=$prefix.$f.$postfix;
    	$files[]=$dir.$f;
    	return $f;
    }
    $i=0;
    function dir_tr($dir)
    {
    	global $i,$w,$tr,$files;
    	$dir=rtrim(trim($dir,'\\'),'/') . '/';
    	$d=@opendir($dir);
    	if(!$d)die('The directory ' .$dir .' does not exists or PHP have no access to it<br><a target="_blank" href="http://forums.phpweby.com">Need help?</a>');
    
    
    	while(false!==($file=@readdir($d)))
    	{
    		if ($file!='.' && $file!='..' && $file!='renamer.php')
    		{
    			if(is_file($dir.$file))
    			{
    				if($w=='' || (strpos($file,$w)!==false))
    				{
    					if(!in_array($dir.$file,$files))
    					{
    						rename($dir.$file,$dir.(prep($file,$dir)));
    						$i++;
    					}
    				}
    			}
    			else
    			{
    				if(is_dir($dir.$file))
    				{
    					if($tr)
    					dir_tr($dir.$file);
    				}
    			}
    		}
    	}
    	@closedir($d);
    }
    dir_tr($dir);
    echo '<br>Renamed ' . $i . ' files in directory<br>' . $dir;
    echo "<br>You can now delete renamer.php";
    echo '<br><br>If you like this software please link to us!<br>Use this code:<br>
        '. htmlspecialchars('<a href="http://phpweby.com/software/filerenamer">PHP file renamer</a>') .'<br>
    	More info and links can be found at <a href="http://phpweby.com/link" target="_blank">http://phpweby.com/link</a><br> ' ;
    echo 'For help, comments, feedback, discussion ... please join our
    	<a href="http://forums.phpweby.com" target="_blank" style="color:blue;font-weight:bold;">Webmaster Forums</a>';
    ?> 
    
    Code (markup):
    And here's the code for listing out the file contents with hyperlinks.
    <?
    /**
     * Change the path to your folder.
     * This must be the full path from the root of your
     * web space. If you're not sure what it is, ask your host.
     * Name this file index.php and place in the directory.
     **/
     // Define the full path to your folder from root
    
        $path = "/www/New directory";
        // Open the folder
        $dir_handle = @opendir($path) or die("Unable to open $path");
        // Loop through the files
        while ($file = readdir($dir_handle)) {
        if($file == "." || $file == ".." || $file == "index.php" )
            continue;
            echo "<a href=\"$file\">$file</a><br />";
        }
        // Close
        closedir($dir_handle);
    	?> 
    Code (markup):
    If you have any doubts. Ask me.


    Effy
     
    efficients, Nov 16, 2008 IP