How to change directory on Windows server using ssh connection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • perlrmhu
    New Member
    • Dec 2011
    • 10

    How to change directory on Windows server using ssh connection

    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_te st directory.
    I tried to use chdir(). It did not work. Followings are the code. Can anyone please help?
    Code:
    #!/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
    Last edited by numberwhun; Dec 20 '11, 07:35 AM. Reason: Please use code tags!
  • perlrmhu
    New Member
    • Dec 2011
    • 10

    #2
    How to change directory on Windows server using ssh?

    I use ssh connection to connect to a Windows server from a Linux server. The connection is made to the E:\FTP working directory. I need to change directory to E:\pilot\dev_te st directory. I run the code as below. I had error on the windows server: "[057] RSSHD 7.00: .\sshd.cpp:Wind owsSessionServe r::HandleProces sExit(8052) Session server 294: Executing command in working directory 'E:\FTP' failed: Child process could not be created." Can anyone please help?

    Code:
    #!/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($stdout, $stderr, $exit) = $ssh->cmd(chdir("E:\pilot\dev_test"));
    Last edited by perlrmhu; Dec 19 '11, 04:26 PM. Reason: provide additional info.

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      Did you mean to have the line commented out that would create the new ssh object?

      Regards,

      Jeff

      Comment

      • perlrmhu
        New Member
        • Dec 2011
        • 10

        #4
        Sorry. That is my mistake. That line should not be commented out. I played around with different ssh connections. I forgot to remove the comment sign when I posted my questions.

        Thanks,

        Randy

        Comment

        • RonB
          Recognized Expert Contributor
          • Jun 2009
          • 589

          #5
          Try using single quotes in the chdir command instead of the double quotes.

          Or, use forward slashes instead of back slashes.

          Comment

          • perlrmhu
            New Member
            • Dec 2011
            • 10

            #6
            RonB, The windows server I want to test the Perl code is down during the holidays. I will try what you suggested as soon as the server is up. thanks,

            Comment

            Working...