WinSCP with Secure Credentials

Advertisement

hroberts65616
Guest

WinSCP with Secure Credentials

I have this script running beautifully with 5.17.10 Automation to upload a file to a server.

My question is and I tried to search for this, is it possible to use a credential file with WinSCP? Either a password in secure text or by using a credential file in xml.

If so how would I add that into the script.
#Load WinSCP .NET assembly
Add-Type -Path "C:\local path\WinSCPnet.dll"
 
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "host or IP address"
    UserName = "username"
    Password = "password"
    SshHostKeyFingerprint = ""
}
 
$session = New-Object WinSCP.Session
 
try
{
    # Connect
    $session.Open($sessionOptions)
 
    # Transfer files
    $session.PutFiles("C:\\localFile.csv", "/remote directory/*").Check()
}
finally
{
    $session.Dispose()
}

Reply with quote

Advertisement

hroberts65616
Joined:
Posts:
1
Location:
USA

I tried the steps in this page:

I tried to follow the steps in this page: https://winscp.net/eng/docs/guide_protecting_credentials_for_automation#powershell

However I am not getting it to work. I have tried it with an XML file and with a CLixml file. I can not get winscp to accept either for me to not have the password in plain text.

Im fairly new to Powershell, but have been scripting on the Linux side for many years.

Thanks all

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
35,438
Location:
Prague, Czechia

Re: I tried the steps in this page:

I'm sorry, but you didn't tell us anything about the problems you are facing. Without any information, all I can do is to repeat everything that's written in the linked article already.

Reply with quote

Advertisement

You can post new topics in this forum