Get-SFTPItem : De opgegeven padindeling wordt niet ondersteund

Fons Ronsmans 21 Reputation points
2022-11-20T16:09:29.5+00:00

I m trying to automate the download files from an SFTP server. It seems connection is ok since the commands like Get_SFTPChildItem shows me exactly what files are on the SFTP host and even GST-SFTPContent works fine.
But Get-SFTPItem ends with an error and I cannot find any solution on Google so far.

$Local = "C:\TEMP"
$Remote = "/"
$password = ConvertTo-SecureString -String $encrypted
$credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $username, $password
$session = New-SFTPSession -Computername $serverIP -Port $serverPort -Credential $credential -AcceptKey
Get-SFTPChildItem -SessionId $session.sessionId
Get-SFTPContent -Path /20221114105631_235259_778533771_1439649_transport.tiflow.accepted_203.xml -SessionId $session.sessionId -ContentType String
Get-SFTPItem -Destination $Local -Path $Remote -SessionId $session.SessionId

Error message:

Get-SFTPItem : De opgegeven padindeling wordt niet ondersteund.
At C:\Users\fons.VERVOERTRANS\Documents\Transporeon SFTP.ps1:13 char:1

  • Get-SFTPItem -Destination $Local -Path $Remote -SessionId $session.Se ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : NotSpecified: (:) [Get-SFTPItem], NotSupportedException
  • FullyQualifiedErrorId : System.NotSupportedException,SSH.GetSftpItem
Windows for business | Windows Server | User experience | PowerShell
{count} votes

Accepted answer
  1. MotoX80 36,401 Reputation points
    2022-11-21T13:14:19.807+00:00

    I have not used those cmdlet's, but the names match regular PS names, so a file copy would be done like this.

    $RemoteFiles = Get-SFTPChildItem  -SessionId $session.sessionId  
    foreach ($Remote in $RemoteFiles) {  
    	"Trying to download $Remote"  
    	Get-SFTPItem -Destination $Local -Path $Remote -SessionId $session.SessionId  
    }	  
    

    If you get an error with the item name, try $Remote.name or $Remote.fullname.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Fons Ronsmans 21 Reputation points
    2022-11-21T08:35:06.82+00:00

    I guess you are right because when I put something like /fons I don't get the error message. I get fons doesn't exist instead :-)
    So now I m asking the SFTP owner what to put in exactly. When I connect with FileZilly I get directly the submap intented for our company. Don't know what pathname it is exactly.
    (./ and ../ don't get it done either, no error messsages but no downloads either.

    thx for your participation.

    0 comments No comments

  2. Fons Ronsmans 21 Reputation points
    2022-11-21T14:17:33.803+00:00

    Thx a lot. And yes I did have to use $Remote.fullname

    Can I ask you one last question. What is the best way (or correct way) to have the files deleted on the host sites once they are downloaded.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.