One of the workaround you can follow ,
To provide the password into the command for upload files to SFTP using PowerShell through Winscp below is the example of code.
cmdltes
:-
Add-Type -Path "WinSCPnet.dll"
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "example.com"
UserName = "user"
Password = "mypassword"
SshHostKeyFingerprint = "ssh-rsa 2048 xx...="
}
$session = New-Object WinSCP.Session
try
{
$session.Open($sessionOptions)
$session.PutFiles("C:\users\export.txt","/Outbox/").Check()
}
finally
{
$session.Dispose()
}
For complete information please refer this BLOG|Use WinSCP to Upload Files to SFTP Site With PowerShell .
For more information regarding similar issue please refer the below links:-