How to move files from one folder to another folder with sftp Perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • perlrmhu
    New Member
    • Dec 2011
    • 10

    How to move files from one folder to another folder with sftp Perl

    I have files in ToTransfer folder on remote windows server. I need to move them to ToTransfre\Tran sferred folder. I am using sftp. The code below did not give me compile error but it did not work either. Can anyone please let know how to get it working?

    Code:
    unless(move("ToTransfer\\$filelist[$li]->{filename}", "ToTransfer\\Transferred"))
                {
                 print "Couldn't move the file to directory ToTransfer\\Transferred\n";
                }
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    The $! variable holds the error from the last executed command. Try making the print line like this and see if it gives you more information:

    Code:
    print "Couldn't move the file to directory ToTransfer\\Transferred:   $!\n";
    If it spits out an error after the :, then see if you can figure out why it isn't working.

    Regards,

    Jeff

    Comment

    • perlrmhu
      New Member
      • Dec 2011
      • 10

      #3
      I added the $! into the print line. I had "No such file or directory". I double-checked the file name and directory. I did not find anything wrong. I tried to use $sftp->move command to move the file. But I get "Can't locate object method "move" via package "Net::SFTP" ". I am wondering if sftp can support the move?

      Comment

      • RonB
        Recognized Expert Contributor
        • Jun 2009
        • 589

        #4
        Why are you using Net::SFTP for moving files on a remote system?

        While it's probably possible to do the move with that module, it's not the proper module for that task. It would be better to use Net::SSH or Net::SSH::Perl.

        Comment

        • numberwhun
          Recognized Expert Moderator Specialist
          • May 2007
          • 3467

          #5
          I definitely agree with @RonB. The Net:SFTP module is for transferring files between your machine and a remote machine, and vice versa, not managing where things are on the remote mating. Take a look at the Net::SSH module that @RonB suggested as its much better suited to the task. You connect to the remote system and then do what you need to do from within your Perl code.

          Comment

          • perlrmhu
            New Member
            • Dec 2011
            • 10

            #6
            thanks to both of you: numberwhun and RonB.

            Comment

            Working...