如何使用 Perl 中的 linux 命令连接到 sftp
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7515348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I connect to sftp using linux command from Perl
提问by bharanikumar Bs
#!/usr/local/bin/perl
use strict;
use warnings;
system("cd $PATH
/usr/bin/sftp mysite.com <<!EOF
put sample.txt
bye
!EPF");
When i complile tha application, it asking the pasword, how to pass the user/password in the code itself,
当我编译应用程序时,它会询问密码,如何在代码本身中传递用户/密码,
what i want is, my script should not ask the password. i want to set the user/password in the code itself. user command not working in sftp How to make it.
我想要的是,我的脚本不应该询问密码。我想在代码本身中设置用户/密码。用户命令在 sftp 中不起作用 如何制作。
采纳答案by Bruce
With such a vague question its hard to give more of an answer…
这么含糊的问题,很难给出更多的答案……
Have you tried the Net::SFTPmodule?
您是否尝试过Net::SFTP模块?
EDIT:
编辑:
Based on the edit to the question - try using Net::SFTP::Foreign
基于对问题的编辑 - 尝试使用 Net::SFTP::Foreign
use Net::SFTP::Foreign;
use warnings;
use strict;
my $host = "xxx.xxx.xxx.xxx";
my $sftp = Net::SFTP::Foreign->new($host, user => 'user', password => 'pass');
$sftp->error and die "Something bad happened: " . $sftp->error;
$sftp->put("sample.txt", "/home/test/test") or die "put failed: " . $sftp->error;
You should get a more meaningful error message and you can take it from there.
您应该会收到更有意义的错误消息,您可以从那里获取它。
回答by runrig
You can try other modules, e.g Net::SFTP::Foreignor the SFTP functionality of Net::SSH2.
您可以尝试其他模块,例如Net::SFTP::Foreign或Net::SSH2的 SFTP 功能。