Showing posts with label copy. Show all posts

Copy multiple files with same name from different directories

I regularly do this. So I automated it.
Below is a small simple script for copying files which are present in two different directories but without same names into a single directory with having name collision.

#!/usr/bin/sh

for i in `find <source_dir_path> -type f`
do
new=`echo $i|nawk -F"/" '{split($NF,a,".");print "<target_dir_path>"a[1]"_"$(NF-1)"."a[2]}'`
cp $i $new
done

Ftp using perl and getting the files based upon a configuration file



I have copied all the file names into one file called "sdk_link.txt" and
I am reading each file name from this and then copying to my local PC:



use strict;
use warnings;


use Net::FTP; 
use File::Copy; 
$Login = "root";
$Pwd = "shroot";
$ftpHost = "tcspava";
$ftpFolder = "/home/tcspava";
$ftp=Net::FTP->new($ftpHost,Timeout=>100);
if ($ftp)  
        {     
        print $ftp->message;
        } 
$ftp->login($Login,$Pwd);
print $ftp->message;
$ftp->cwd($ftpFolder);
print $ftp->message;
open FILE,"sdk_link.txt" or die $!;
while($test=<FILE>)  
{     chomp($test);
      #Copy the file     
      copy("$test","/testing");
} $ftp->quit;