Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 使用Net::SFTP::Foreign重命名远程文件_Perl_Sftp_Move - Fatal编程技术网

Perl 使用Net::SFTP::Foreign重命名远程文件

Perl 使用Net::SFTP::Foreign重命名远程文件,perl,sftp,move,Perl,Sftp,Move,我正在使用下面的脚本重命名远程主机上的文件。我想连接到远程计算机,然后重命名远程服务器上的文件 #!/u01/app/perl-5.28/bin/perl use strict; use Net::SFTP::Foreign; my %dirlist; my $host='x.x.x.x'; my $sftp; my $RemFile="/tmp/tempfile"; my %args = ( user => 'netcrk', password => '

我正在使用下面的脚本重命名远程主机上的文件。我想连接到远程计算机,然后重命名远程服务器上的文件

#!/u01/app/perl-5.28/bin/perl

use strict;
use Net::SFTP::Foreign;

my %dirlist;
my $host='x.x.x.x';
my $sftp;
my $RemFile="/tmp/tempfile";
my %args = (
    user     => 'netcrk',
    password => '*******',
    #more     => '-v',
    autodisconnect => 0
);



sub ConnToSftpHost
{
 my $h=shift;
 print "Connecting to host $h \n";
 $sftp = Net::SFTP::Foreign->new($h, %args);   # Check whether succeeded or failed!
 if ( $sftp->error ) {
     die qq(Could not establish the SFTP connection);
 }
 $sftp->die_on_error("SSH connection failed");
}

sub RenameRemFile
{
   my $old=shift;
   my $new=$old.".Finish";
   print "Renaming Old File: $old \n";
   $sftp=>rename($old,$new);
}

ConnToSftpHost($host);
RenameRemFile($RemFile);
$sftp->disconnect;

$ ./renamesftp.pl
Connecting to host x.x.x.x
Renaming Old File: /tmp/tempfile
$
我可以看到文件没有被重命名,也没有抛出错误。
有谁能帮我一下这里有什么问题吗

这里可能有个打字错误:
$sftp=>重命名($old,$new)不应该是
$sftp->rename($old,$new)@Chris,你说得对:)谢谢。