-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New-WinSCPSession: You cannot call a method on a null-valued expression #131
Comments
if I had to take a guess, I bet its something with this: |
After a reboot it works is the thing so I know the variables are good, it's only when I open a 2nd script containing the same formatted code with different variable for another SFTP site that it breaks and going back to the original script that was working after the reboot it is then broken. If you don't plan on making any updates anytime soon do you have any alternative recommendations for SFTP in powershell? |
im trying to get this updated, I have to re write all my pester test because pester was completely refractored, I just haven't had time, and I have been using Mac for the past year or more, so this thing doesn't do me much good any more. can you dump all you're variables from the second script. Based on the error, some value is $null, and that is where the issue is. I don't think its with any logic in the code. |
None of the variables in my script are empty, even the $credential data is in the $sessionsoptions variable. I also just tried removing as many variables as I could and still get the error: $sessionoptions = New-WinSCPSessionOption -HostName "my.sftp.com" -Protocol "sftp" -PortNumber 22 -Credential (Get-Credential) -SshHostKeyFingerprint "ssh-rsa 2048 00:00:00:00:00:00:00:00:00:00..." Error: New-WinSCPSession : You cannot call a method on a null-valued expression |
Can you clone this repo, and load up the latest version. Im still trying to get the build pipeline working so I can publish it. But one of the biggest thing is that it will now load up the proper dll, based on Core or Desktop pwsh versions. Also has the latest version of the dlls. |
whats the best way to load the module? do I copy this into C:\program files\windowspowershell\modules\winscp\5.17.5.4" |
you can just put it on your desktop and use the -Path parameter, make sure to start a new session or you will need to add the -Force Parameter as well. |
first few tests are working, let me add this to a few other scripts |
2nd test I get an error I am doing Remove-WinSCPSession at the end of each session also. And even with these errors it is still connecting and downloading the files. |
you need to re start your powershell session, its trying duplicate the aliases when importing the module, or you can use -Force when you import the module. |
ok that takes care of that error |
is it good to say the updated code fixes this error? I ma about half way through my pester rewrites, so I hopping to have the build pipeline back up and running sometime next week to get this to the PSGallery. |
Yes so far everything seems to be working.
…On Sat, Aug 22, 2020, 1:34 PM Thomas Malkewitz ***@***.***> wrote:
is it good to say the updated code fixes this error? I ma about half way
through my pester rewrites, so I hopping to have the build pipeline back up
and running sometime next week to get this to the PSGallery.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#131 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIFJNCNNQT52TQRMFVSMI2DSCATWZANCNFSM4QD352DQ>
.
|
well, took all weekend, but the build pipeline seems to be restored lol. had to re write 120+ Pester tests to work from v3 to v5. Anyway, its published to the gallery and the releases here. im going to close this. thanks. |
Please fill in the following fields, replacing the values inside the brackets
{{ }}
.Issue Description
My SFTP code has stopped working and I'm getting conflicting results. If I reboot my server and run the script it works over and over but if I open a new .ps1 with the same script it starts erroring with "New-WinSCPSession: You cannot call a method on a null-valued expression"
Example
Import-Module -Name WinSCP -RequiredVersion 5.17.5.3
$Credential = Import-CliXml “C:\Creds\Account.xml”
$Hostname = "my.sftp.net"
$Protocol = "sftp"
$Port = 22
$HostKeyFingerprint = "ssh-rsa 2048 1c:2f:3f:13:........."
$SessionOptions = New-WinSCPSessionOption -HostName $Hostname -Protocol $Protocol -PortNumber $Port -Credential $Credential -SshHostKeyFingerprint $HostKeyFingerprint
$Session = New-WinSCPSession -SessionOption $SessionOptions
if ($session){
Receive-WinSCPItem -WinSCPSession $Session -RemotePath "/export/file.csv" -LocalPath "C:\Data\file.csv"
Remove-WinSCPSession -WinSCPSession $session
}
Expected Output
I expect a successful connection
Actual Output
After a reboot the script runs fine, I can run it over and over but if I open the script in another .ps1 instance I get an error "New-WinSCPSession: You cannot call a method on a null-valued expression" if I go back to the working .ps1 I start getting the error on that script also.
WinSCP-PowerShell Version
5.17.5.3
Environment
Windows 2019 10.0.17763
PSVersion: 5.1.17763.1007
FTP Server: CerberusFTPServer_11.0
The text was updated successfully, but these errors were encountered: