This module can be installed from the PowerShellGet Gallery, You need WMF 5 to use this feature.
# To install WinSCP, run the following command in the PowerShell prompt in Administrator mode:
Install-Module -Name WinSCPThis module can be installed with chocolatey:
choco install winscp.powershell -version 5.7.3.2
This module can be installed with PsGet:
# Install WinSCP module with PsGet
Install-Module -ModuleUrl "https://github.com/dotps1/WinSCP/raw/master/WinSCP.zip" -ModuleName WinSCP -Type ZIP- Add-WinSCPSessionOptionsRawSettings
- Close-WinSCPSession
- ConvertTo-WinSCPEscapedString
- Get-WinSCPDirectoryContents
- Get-WinSCPFileChecksum
- Get-WinSCPItemInformation
- Invoke-WinSCPCommand
- Move-WinSCPItem
- New-WinSCPDirectory
- New-WinSCPFilePermissions
- New-WinSCPSessionOptions
- New-WinSCPTransferOptions
- Open-WinSCPSession
- Receive-WinSCPItem
- Remove-WinSCPItem
- Send-WinSCPItem
- Start-WinSCPConsole
- Sync-WinSCPDirectory
- Test-WinSCPItemExists
Example 1:
# Splat New-WinSCPSessionOptions.
$sessionOptions = @{
HostName = "myftphost.org"
UserName = "ftpuser"
Password = "FtpUserPword"
SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
}
# Open a new WinSCPSession using the splatted parameters.
$session = Open-WinSCPSession -SessionOptions (New-WinSCPSessionOptions @sessionOptions)
# Use that session to create a new Directory and then upload a file to it.
New-WinSCPDirectory -WinSCPSession $session -Path "./remoteDirectory"
Send-WinSCPItem -WinSCPSession $session -LocalPath "C:\localDirectory\localFile.txt" -RemotePath "./remoteDirectory/"
# Close the session.
Close-WinSCPSession -WinSCPSession $sessionExample 2:
# Create session, download a file, and close the session in one line.
# If the WinSCP.Session Object is passed through the pipeline it will be auto-closed upon the completion of that command.
# To avoid this behaviour, set the WinSCP.Session object value to variable to be reused.
Open-WinSCPSession -SessionOptions (New-WinSCPSessionOptions -HostName "myftphost.org" -UserName "ftpUser" -Password "MyPassword" -Protocol Ftp) | Receive-WinSCPItem -RemotePath "./file.txt" -LocalPath "C:\folder\"This is still a very beta version, with most of the functionality available with WinSCP, I intend on developing this extensively.
I have included the WinSCPnet.dll in the NeededAssemblies folder.
Check back regularly for updates.
this project is licensed with GNU GENERAL PUBLIC LICENSE.