Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    12
    Rep Power
    0

    Perl code to copy file from one server to another


    Can anyone help me with a code or script which copies file from one server to another.....Thanks in advance for your help
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    776
    Rep Power
    495
    Which operating system? What protocol are you planning to use for copying the files? FTP? SFTP? rcp? Other?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    12
    Rep Power
    0
    We will be using SFTP. So any help?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,873
    Rep Power
    1225
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    12
    Rep Power
    0
    Thanks for the help. Can someone help me uncompressing different kinds of file in perl. I mean, how to uncompress 7za, zip, tar, gz, bz2, tgz files. If someone can show a few sample script, it will be very useful. Thanks
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    776
    Rep Power
    495
    Take a look at this:

    Zip Module
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    25
    Rep Power
    0
    Originally Posted by Sourabhbms
    Can someone help me uncompressing different kinds of file in perl. I mean, how to uncompress 7za, zip, tar, gz, bz2, tgz files.
    You can use Archive::Extract

    It's a lot simpler to use.

    If someone can show a few sample script, it will be very useful. Thanks
    Check the SYNOPSIS of the module pointed to.

    Hope this helps.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    12
    Rep Power
    0
    Please help me . I have n number of files in a directory, and out of those i have, suppose 3 tar file. Requirement is to read those file and if get a tar one, then extract it.

    opendir(DIR,$dir) or die $!;
    while (my $file=readdir("DIR"))
    {
    ---------
    ---------------
    }
    closedir(DIR);
    exit 0;

    What should I add in the while block to extract only tar files, or is there any way that readdir would read only tar files. Any help would be appreciated
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    776
    Rep Power
    495
    You can filter the files at the top of your while loop:

    Perl Code:
    while (my $file=readdir("DIR"))
    {
         next unless $file =~ /\.tar$/;
         # ...


    Or you could use the glob function instead of the readdir function:

    Perl Code:
    my @files = glob ("$dir/*.tar");
    for my $file (@files) {
         # ...
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    12
    Rep Power
    0
    This worked. Thank you very much...
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    12
    Rep Power
    0
    Need a little help, on top of that, if i want to extract those tar files how to do that,

    if i try to archive those files, it saying "could not create file handle". I also tried "while unless". for normal actions it s fine, like printing , but for tar/archive/extraction its not working. Please help
  22. #12
  23. 'fie' on me, allege-dly
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,889
    Rep Power
    6444
    Archive::Zip could be a start, there should be something in CPAN for this
    --Ax
    without exception, there is no rule ...
    Handmade Irish Jewellery
    Targeted Advertising Cookie Optout (TACO) extension for Firefox
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones


    09 F9 11 02
    9D 74 E3 5B
    D8 41 56 C5
    63 56 88 C0
    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
    -- Jamie Zawinski
    Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
    BIT COINS ANYONE
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    776
    Rep Power
    495
    Try also Archive::Tar.
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    12
    Rep Power
    0
    Hi, Please help me debug this code

    The code should extract all the tar files in current directory, but is not working

    use Cwd;
    use Archive::Extract;
    use Archive::Tar;
    my $tar = Archive::Tar->new;

    my $dir=cwd();
    opendir(DIR,$dir) or die $!;
    while (my $file=readdir("DIR"))
    {
    next unless $file=~ /\.tar$/;
    $tar->extract_archive('$file');
    print "$file\n";

    }
    closedir(DIR);
    exit 0;


    It is giving an error as:
    Could not create filehandle for '$file': No such file or directory! at check.pl
    line 11

    Can you explain, what to do as I am a newbie.

    Regards,
    Sourabh
  28. #15
  29. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,221
    Rep Power
    1809
    Don't put single quotes around the variable $file. They prevent it from being interpreted.

    Code:
    while (my $file=readdir(DIR)) {
    	next unless $file=~ /\.tar$/;
    	$tar->extract_archive($file);
    	print "$file\n";
    }
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo