Posh-SSH
Posh-SSH copied to clipboard
Impossible to Finalyse my SFTP script
hello DarkOp ive a few question for you. I need to Get a file from a distant SFTP server to a remote Local path Im using Posh SSH 3.0.8
here's my script (he call a conf file)
#Import du fichier de Configuration du Script Import-LocalizedData -BaseDirectory "XXX" -filename conftest.psd1 -erroraction Stop
#Variabilisation du fichier d'import $configfile = Import-LocalizedData -BaseDirectory "XXX" -filename conftest.psd1 -erroraction Stop
#Load Credential from config file $creduser = $configfile.sftpuser $credpass = ConvertTo-SecureString $configfile.sftppassword -AsPlainText -Force $Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $creduser,$credpass
Establish the SFTP connection
$SFTPSession = New-SFTPSession -ComputerName $configfile.Sftphost -Port $configfile.Sftpport -Credential $Credential | fl
lists directory files into variable
Get-sftpsession | fl Get-SFTPCurrentDirectory -Index 0 Set-SFTPDirectoryPath -Index 0 -Path /RCTE
#Get Sftp file into Local directory Get-SFTPFile -SessionId $session.SessionID -RemoteFile $configfile.Sftppath -LocalPath $configfile.Localpath -Overwrite
#Terminates the SFTP session on the server Remove-SFTPSession -index 0
Im able to Connect to the remote directory but Impossible to Get the file i get an error for the SessionID parameter (.SessionID)
Can you Help me ?
Thanks
remove | fl
from $SFTPSession = ...
and use $sftpsession everywhere, for ex. Get-SftpItem -SftpSession $SFTPSession
and do not use | fl
in scripts if you assign in to variables