469,341 Members | 6,582 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,341 developers. It's quick & easy.

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\Transferred 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?

Expand|Select|Wrap|Line Numbers
  1. unless(move("ToTransfer\\$filelist[$li]->{filename}", "ToTransfer\\Transferred"))
  2.             {
  3.              print "Couldn't move the file to directory ToTransfer\\Transferred\n";
  4.             }
Dec 29 '11 #1
5 3951
3,503 Expert Mod 2GB
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:

Expand|Select|Wrap|Line Numbers
  1. 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.


Jan 2 '12 #2
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?
Jan 2 '12 #3
589 Expert Mod 512MB
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.
Jan 2 '12 #4
3,503 Expert Mod 2GB
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.
Jan 3 '12 #5
thanks to both of you: numberwhun and RonB.
Jan 3 '12 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by neilmcguigan | last post: by
3 posts views Thread by =?Utf-8?B?UHVyZSBIZWFydA==?= | last post: by
1 post views Thread by ajames270 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.