Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am very new to Perl scripting. I am trying to do SFTP using Perl Script and able to login into Host machine using perl script. But when I try changing the directory on Host machine its not do it. Here are the commands I used,

$ftp=Net::SFTP::Foreign->new($host,%args) or $newerr=1; $ftp->setcwd($hostgetdir) or $newerr=1; print "===================\n", getcwd(), "\n", "Done!\n", "===================\n";

This is changing it to local directory but not on the Host Machine. Please help what command i have to use.

Regards
Sudeep

2018-08-02 Athanasius added code and paragraph tags

Replies are listed 'Best First'.
Re: Change to the Host directory in SFTP using Perl Script
by Corion (Patriarch) on Jul 31, 2018 at 14:34 UTC

    Where in the code you show do you set $hostgetdir?

    Also, getcwd() will only ever show the local directory and never the remote directory. See Net::SFTP::Foreign for the ->cwd method to find the current working directory of the remote session.

Re: Change to the Host directory in SFTP using Perl Script
by sverma77 (Initiate) on Jul 31, 2018 at 14:32 UTC
    Hi, Can anyone please help me how to change to a Host Directory in Perl Scripts using SFTP connection. Regards Sudeep