I am trying to access remote server via SFTP. I am using Net::SFTP::Foreign for this. Problem arises when I try to change directory to to user's home directory. It is not allowing to change directory as in shell.
cd ~
cd ~/folder
My perl code is as follows.
$sftp->setcwd("~/aast-backup/$backup_type") or die "unable to change cwd: " . $sftp->error;
unable to change cwd: Couldn't get realpath for remote '/home/ftpkasi/aast-backup/~/aast-backup/differential
Please show some light into this. Thanks in advance...
The answer is in the documentation for the cwd
method:
$sftp->cwd
Returns the remote current working directory.
When a relative remote path is passed to any of the methods on this package, this directory is used to compose the absolute path.
So the relative path you're passing to setcwd
is being appended to your initial cwd
. You can see this in the error message you get. The initial cwd
is
/home/ftpkasi/aast-backup/
and when you call
$sftp->setcwd("~/aast-backup/$backup_type")
it tries to change to the directory
/home/ftpkasi/aast-backup/~/aast-backup/differential
which obviously doesn't exist.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.