vickey110 has asked for the wisdom of the Perl Monks concerning the following question:

I have a directory named systems which contains two more directories system1 and system2 and each of these directory contains bunch of files. Out of those I need to export only .csv files to my local machine as I am working on Unix in Putty. Using the scp command as

 scp /user/vickey/systems/system1/file1.csv vickeys@localhost:C:/

but copying each file one by one is taking too long. Could anyone suggest how I can do the same using a Perl script without editing the file name each time.

Replies are listed 'Best First'.
Re: copying file from one server to other
by salva (Canon) on Oct 17, 2017 at 07:47 UTC
    You can copy as many files as you want in one command as far as the destination folder is always the same:
    scp /user/vickey/systems/system1/file1.csv /user/vickey/systems/system +1/file2.csv ... vickeys@localhost:C:/
    Or just...
    scp /user/vickey/systems/system1/file*.csv vickeys@localhost:C:/
    Anyway, there are several modules that would allow you to do that from Perl: for SCP, you can use Net::OpenSSH or Net::SSH::Any (Net::SSH2 also supports SCP but it is buggy). Another option is to do the transfers using SFTP protocol that is much richer than SCP and allows more advanced operations, for that you can use Net::SFTP::Foreign.

    Then, you also have WinSCP that you can install in your Windows machine in order to transfer files from the Unix server using a friendly graphical interface.

Re: copying file from one server to other
by Discipulus (Canon) on Oct 17, 2017 at 07:45 UTC
    Hello vickey110 and welcome to the monastery and to the wonderful world of Perl!

    Well.. post are more welcome when they contain some Perl effort from part. If you show us what you tried monks can adjust their help based on your skill. Infact probably will be not so useful for you if i had answered something like: perl -le "system qq(prog $_) for glob $ARGV[0]" *.csv no?

    If you want to create a perl program to process many files be sure to use strict and use warnings at the top of the program.

    After you can profit of the glob function to build up a list of all .csv files. Then you can build up a foreach loop to process them.

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: copying file from one server to other
by thanos1983 (Parson) on Oct 17, 2017 at 08:19 UTC