How to Connect to Sftp Using Linux Command from Perl

How can I connect to sftp using linux command from Perl

With such a vague question its hard to give more of an answer…

Have you tried the Net::SFTP module?

EDIT:

Based on the edit to the question - try using 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.

How to use SFTP command in perl?

Here is the answer that how I solve the problem I met. Thanks!

 if ( open(SENDFILE,">$sendFile") ) 
{
print SENDFILE "get hk_test.txt\n";
print SENDFILE "put hk.txt\n";
print SENDFILE "quit\n";
}
close (SENDFILE);

`sftpg3 -q -B $sendFile user\@host`;

Perl - Best way to establish an SFTP connection on windows

The preferred way to use Net::SFTP::Foreign in Windows is probably to use the Net::SFTP::Foreign::Backend::Net_SSH2 backend (update: a Perl module available from CPAN) which uses Net::SSH2 under the hood (which is already included with Strawberry Perl, update: otherwise, you will need to build and install libssh2 yourself which sometimes is not as easy as it should be).

Another option is to tell Net::SFTP::Foreign to use the plink command to run the SSH connection (search for plink on the module docs). Update:plink is part of the PuTTY application distribution, a very popular SSH client that may be already installed in that machine.

Finally you can also try using Net::SSH::Any which provides its own backend for Net::SFTP::Foreign and can run on top of several SSH clients and modules... but it is still in beta!

How to set the transfer mode to ASCII in SFTP (version 3) using Perl

Using Net::SFTP::Foreign:

$sftp->put($local_from, $remote_to, conversion => 'unix2dos');

See On the fly data conversion.

Using SFTP to transfer images from HTML form to remote linux server using PERL/CGI.pm

use CGI qw(:standard);
use File::Basename;
my ( $name, $path, $extension) = fileparse ( $productimage, '..*' );
$productimage = $name . $extension;
$productimage =~ tr/ /_/; $productimage =~ s/[^$safechars]//g;
if ( $productimage =~/^([$safechars]+)$/ ) {
$productimage = $1;
} else {
die "Filename contains invalid characters";
}

$fh = upload('image');
$uploaddir = "../../.hidden/images";
open ( UPLOADFILE, ">$uploaddir/$productimage" )
or die "$!"; binmode UPLOADFILE;

while (<$fh>) {
print UPLOADFILE;
}

close UPLOADFILE;

This is the code I used to upload the file into the server.



Related Topics



Leave a reply



Submit