- martin
Post a reply
Topic review
- Follow-up
But that would mean putting the credentials in clear text in the script?
- martin
There's indeed no
WinSCP .NET assembly in general does not use GUI configuration. It's completely isolated.
You have to configure the session in the script using
https://winscp.net/eng/docs/library_from_script#default_config
Site
parameter.
WinSCP .NET assembly in general does not use GUI configuration. It's completely isolated.
You have to configure the session in the script using
SessionOptions
properties.
https://winscp.net/eng/docs/library_from_script#default_config
- OP
Martin, thanks. I'm not having success that way. I get this error:
I'm guessing it doesn't like this:
I have my site defined in the GUI. How do I invoke it as a property of
New-Object : The member "Site" was not found for the specified .NET object.
At line:5 char:23
+ $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.NewObjectCommand
Error: Exception calling "Open" with "1" argument(s): "Value cannot be null.
Parameter name: sessionOptions"
I'm guessing it doesn't like this:
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Site = "MySiteName"
}
I have my site defined in the GUI. How do I invoke it as a property of
SessionOptions
?
- martin
Re: How to get the results of LS into a variable
In PowerShell, do not use scripting. Use WinSCP .NET assembly:
https://winscp.net/eng/docs/library_powershell
Then you can use
https://winscp.net/eng/docs/library_session_listdirectory
https://winscp.net/eng/docs/library_powershell
Then you can use
Session.ListDirectory
to retrieve contents of a remote directory to a variable.
https://winscp.net/eng/docs/library_session_listdirectory
- AssistanceRequested
How to get the results of LS into a variable
I want to automate the following:
Automation works fine. I can open my defined site, create directories, upload and download files. I'm guessing
How can I accomplish this?
- Open my defined site
- Run
ls
—which is a supported command—and have the output from it go to a variable, a file, *anything* that I can then read back into the next step of my PowerShell script.
Automation works fine. I can open my defined site, create directories, upload and download files. I'm guessing
ls
is working just fine, but there's no obvious way to capture the output.
How can I accomplish this?