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

<c> #! /usr/bin/env perl use strict; use warnings; use feature qw(say); use autodie; use Net::SFTP::Foreign; use constant { HOST => "sftp.elsvier.com", REMOTE_DIR => "sample/host", LOCAL_DIR => "sample/local", USER_NAME => "username", PASSWORD => "password", DEBUG => "0", }; my $sftp; $stfp = Net::SFTP::Foreign->new ( HOST, timeout => 240, user => USER_NAME, password => PASSWORD, autodie => 1, ); # # Fetch Files # $sftp->rget( REMOTE_DIR, LOCAL_DIR ); # # Delete Files # $sftp->setcwd( REMOTE_DIR ); my @files = @{ $sftp->ls }; #Returns a reference to an array of hashe +s $sftp->disconnect;
</c>
  • Comment on how to transfer a set of files in a directory from linux server(remote machine) to windows server(local machine)
  • Download Code

Replies are listed 'Best First'.
Re: how to transfer a set of files in a directory from linux server(remote machine) to windows server(local machine)
by mah_strict (Novice) on Apr 21, 2014 at 12:50 UTC
    I am getting the following error in windows when i try to run it through command prompt. In the host i have given the corresponding host name and other credentials. The error is as follows

    C:\temp\perl_test\mahe>perl mah.pl Unrecognized escape \m passed through at mah.pl line 13. Having no space between pattern and following word is deprecated at mah.pl line 31. Bareword found where operator expected at mah.pl line 31, near "/export/home" (Missing operator before home?) Backslash found where operator expected at mah.pl line 31, near "perl_test\" Global symbol "$stfp" requires explicit package name at mah.pl line 20. syntax error at mah.pl line 24, near "/," syntax error at mah.pl line 31, near "/export/home" Execution of mah.pl aborted due to compilation errors.

      If you want to put windows paths as for instance c:\foo\bar inside double quotes, you have to escape the backslashes ("c:\\foo\\bar").
Re: how to transfer a set of files in a directory from linux server(remote machine) to windows server(local machine)
by GotToBTru (Prior) on Apr 21, 2014 at 12:42 UTC

    Please surround your code with <c> and </c> tags to make it readable. Also, what errors are you getting specifically?

Re: how to transfer a set of files in a directory from linux server(remote machine) to windows server(local machine)
by mah_strict (Novice) on Apr 21, 2014 at 12:13 UTC
    I am actually new to perl and i am feeling difficult as i am getting lot of errors.Please can anyone help
      Please, clean up your original post by adding <code>...</code> tags around the code,so its more easily readable.

      Then specify what errors you are seeing... verbatim!

      Update: removed recommendation to insert strict and warnings. OP has 'em, but I blanked on them in the face of the unformatted code. Bad on /me.


      Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
      1. code
      2. verbatim error and/or warning messages
      3. a coherent explanation of what "doesn't work actually means.

      check Ln42!

Re: how to transfer a set of files in a directory from linux server(remote machine) to windows server(local machine)
by mah_strict (Novice) on Apr 21, 2014 at 13:09 UTC
    ok What about the other error.Even though i have used the Net::SFTP::FOREIGN i am getting a error \" Global symbol "$stfp" requires explicit package name at mah.pl line 20. What does this mean??

      On line 19 you declare my $sftp; but then on line 20 you assign to $stfp = Net::SFTP::Foreign->new. Note the transposition of f and t.

      As an aside, this is one the benefits of use strict; it will catch these kinds of spelling errors at compile time.

Re: how to transfer a set of files in a directory from linux server(remote machine) to windows server(local machine)
by mah_strict (Novice) on Apr 21, 2014 at 13:20 UTC
    Can anyone please tell the solution to the above error. It is the only error i am getting right now and rest all errors are rectified
      I think you meant (in your code) "$sftp" instead of "$stfp".

      Cheers,
      Rob
Re: how to transfer a set of files in a directory from linux server(remote machine) to windows server(local machine)
by mah_strict (Novice) on Apr 21, 2014 at 14:05 UTC
    Now I am getting this error How should I install that module from perl package manager???? password authentication not available, IO::Pty is not installed or failed to loa d: Can't locate IO/Pty.pm in @INC (@INC contains: P:/Apps/Perl/site/lib P:/Apps/ Perl/lib .) at P:/Apps/Perl/site/lib/Net/SFTP/Foreign/Backend/Unix.pm line 256. at mah.pl line 20
        Can u please suggest any other module to get files from one server to another server in perl??
Re: how to transfer a set of files in a directory from linux server(remote machine) to windows server(local machine)
by mah_strict (Novice) on Apr 22, 2014 at 10:43 UTC
    I am unable to install net::ssh2 using perl package manager. Is there any other alternative. Can i use ftp to transfer files from one server to another..? Please suggest

      Install via cpan:

      cpan Net::SSH2

      You don't say which Version of Perl you have, perhaps you may need to setup a sane development environment.

Re: how to transfer a set of files in a directory from linux server(remote machine) to windows server(local machine)
by mah_strict (Novice) on Apr 22, 2014 at 11:20 UTC
    This is perl 5, version 14, subversion 2 (v5.14.2) built for MSWin32-x86-mult hread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2011, Larry Wall This version I am having . Can i do the file transfer using ftp ?? pls guide
        I am unable to install ssh2. I am trying to install all the modules using perl package manager. I am stuck in this problem from one week. And I am sorry for the above comments.