Skip to content
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

Copy-WinSCPItem fails with null path #157

Open
krylon opened this issue Oct 19, 2023 · 3 comments
Open

Copy-WinSCPItem fails with null path #157

krylon opened this issue Oct 19, 2023 · 3 comments
Assignees

Comments

@krylon
Copy link

krylon commented Oct 19, 2023

Please fill in the following fields:

Issue Description

Copy-WinSCPItem fails when attempting to copy a file

Example

Copy-WinSCPItem -Path /tmp/test1.txt -Destination /tmp/test2.txt

Expected Output

A copy of /tmp/test1.txt is made and written to /tmp/test2.txt

Actual Output

Cannot bind argument to parameter 'Path' because it is null.

WinSCP-PowerShell Version

6.1.2.0

Environment

Windows 10
PowerShell 5.1
WinSCP session is SCP
Session option also includes SSHhoskeypolicy = 'AcceptNew'

@krylon
Copy link
Author

krylon commented Oct 19, 2023

It looks like inside Copy-WInSCPItem you are validating the destination path\file first and a call is failing inside Get-WinSCPItem on line 52 using:

$WinSCPSession.GetFileInfo($pathvalue)

$pathvalue would be the new destination file and its not present yet.

@tomohulk
Copy link
Owner

tomohulk commented Oct 20, 2023

I'll have to think about this, and try some refactoring. the -Destination should be a directory, not a full file path. But, I think it should support this. So I'll have to refactor that function a bit. Thanks for letting me know.

@tomohulk tomohulk self-assigned this Oct 20, 2023
@jojomueller05
Copy link

jojomueller05 commented Aug 30, 2024

I've had a similar issue. I've used the Get-WinSCPChildItem
with the -Filter parameter. This returned me an array of objects.

The files and folders which should get ignored by the filter are represented with $null
in the returned array. Therefore, the following cmdlets failed ( in my case
Receive-WinSCPChildItem).

I've fixed it by removing the $null values from the array. Here is an example:

# ...
# define filters
$types = @("*.csv", "*.xls*", "*.txt")

# get files on the remote
$files = foreach($type in $types){
	Get-WinSCPChildItem -Path $Source -Filter $type -WinSCPSession $Session 
}

# ...

# Remove $null values from $files 
$files | Select-Object {$_ -ne $null}

# Download files 
Receive-WinSCPChildItem -RemotePath $files -LocalPath $Destination -WinSCPSession $Session

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants