Trying to upload file to sftp server with powershell

Here are my various attempts, and all the errors I have encountered.

Cannot load module:

Add-PSSnapin KTools.PowerShell.SFTP

Add-PSSnapin : Cannot load Windows PowerShell snap-in KTools.PowerShell.SFTP because of the following error: Could not
load file or assembly 'file:///C:\Program Files\KTools\KTools.PowerShell.SFTP\bin\KTools.PowerShell.SFTP.dll' or one of
 its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At line:1 char:2
+  Add-PSSnapin KTools.PowerShell.SFTP
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (KTools.PowerShell.SFTP:String) [Add-PSSnapin], PSSnapInException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

The same goes for winscp:

PS C:\Users\user\Desktop> Add-Type -Path "C:\Users\user\Documents\WindowsPowerShell\Modules\WinSCP\NeededAssemblies\
Add-Type : Could not load file or assembly 'file:///C:\Users\user\Documents\WindowsPowerShell\Modules\WinSCP\NeededAs
semblies\WinSCPnet.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At line:1 char:1
+ Add-Type -Path "C:\Users\user\Documents\WindowsPowerShell\Modules\WinSCP\Neede ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Type], FileLoadException
    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand

Tried to use

$sftpUser = "user"
$sftpPass = ConvertTo-SecureString -String "pass" -AsPlainText -Force
$sftpCred = new-object -typename System.Management.Automation.PSCredential -argumentlist $sftpUser, $sftpPass
$sftpSession = New-SFTPSession -ComputerName -Credential $sftpCred
Set-SFTPFile -SFTPSession $sftpSession -LocalFile "E:\CSV to ftp\test file.csv" -RemotePath "/files/register" -Overwrite

Set-SFTPFile : Object reference not set to an instance of an object.
At line:6 char:1
+ Set-SFTPFile -SFTPSession $sftpSession -LocalFile ""E:\CSV to ftp\test file.csv ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-SFTPFile], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,SSH.SetSftpFile
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Peter HutchisonSenior Network Systems SpecialistCommented:
What version of Windows are you using and what version of Powershell are you using?
You can find out what version of Powershell you are using by typing <b>Get-Host</b> . You need at least 3.0 for these modules.
itniflAuthor Commented:
I don't have the sytem in front of me right now, but judging by the start menu it was Windows Server 2012 R2 and if I remember correctly, the powershell version was 4.0. I will double check that tomorrow, but I guess 2012 servers don't come with powershell less then the required 3.0
itniflAuthor Commented:
Yes, 2012 R2 with Powershell 4.0
Peter HutchisonSenior Network Systems SpecialistCommented:
Try running powershell shell with the parameter -version 3.0 and then see if the module loads.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
itniflAuthor Commented:
To get Add-PSSnapin KTools.PowerShell.SFTP to work, I found to be helpful. I bet WinSCP would work as well now.

Set-SFTPFile still returns a null pointer exception. But I don't need it now that KTools.PowerShell.SFTP works.
Maybe Set-SFTPFile would work better under 3.0 as you suggest?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.