Skip navigation.
Home
Your source for Perl tips, howto's, faq and tutorials
( categories: )

I use ssh password-less connection to connect to a Windows server from a Linux server. The connection is made to the E:\FTP working directory. I did a dir to list the file in the working directory. I had no output. I need to change directory to E:\pilot\dev_test directory.
I tried to use chdir(). It did not work. Followings are the code. Can anyone please help?

#!/usr/local/bin/perl
use Net::SSH::Perl;
use Net::SCP::Expect;

my $remote_host = "remote_Windows_server.com";
my $user = "aacesrdev";
#my $ssh = Net::SSH::Perl->new($remote_host, debug => 1, identity_files =>["/home/aacesrdev/.ssh/id_rsa"], protocol=>'2,1');
$ssh->login($user);

my $cmd = "dir";
my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
print "stderr= $stderr\n";
print "stdout= $stdout\n";
print "exit = $exit\n";

my($stdout, $stderr, $exit) = $ssh->cmd(chdir("E:\pilot\dev_test"));
print "stderr= $stderr\n";
print "stdout= $stdout\n";
print "exit = $exit\n";

The outputs are as below:
stderr=
stdout=
exit = 8772

stderr=
stdout=
exit = 8772


See the note below from

See the note below from Net::SSH::Perl

NOTE: the SSH-1 protocol does not support
running multiple commands per connection, unless those commands are chained together so that the remote shell can evaluate them. Because of this, a new socket connection is created each time you call cmd, and disposed of afterwards.

I suggest you make sure you are not using SSH-1 protocol version.