I am trying to send files from local to remote using Putty's PSCP command using powershell.
pscp -pw somepassword D:\path\to\file.xlsx user@server123:/path/to/remote/directory
However, I get an "Access Denied" message followed by a prompt to enter the user's password. After entering the password, the file transfer works. I need to find a way to not have to manually enter the password every time as this is supposed to be an automation.
CodePudding user response:
I assume that somepassword
has characters considered as special by PowerShell, so you first receive Access Denied because the password is incorrect. In this case try to use the following two commands:
$mypassword = 'somepassword'
pscp -pw $mypassword 'D:\path\to\file.xlsx' 'user@server123:/path/to/remote/directory'
Note that single quotes are used around the password, paths and the URL.
Then I think that it makes sense to remove the $mypassword
variable using the Remove-Variable mypassword
command.
PS Perhaps pscp -pw 'somepassword' 'D:\path\to\file.xlsx' 'user@server123:/path/to/remote/directory'
will also work for you.