Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

You have to set it to "true", not "false".
rvjhon

Hi,

Sorry i dont know use this value.
Where i put this value $sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey

regards mister

[Reflection.Assembly]::LoadFrom("WinSCPnet.dll") | Out-Null
$srv = Get-Content "z:\projet_enable\liste_serveur.txt"
$mdp = Get-Content "z:\projet_enable\liste_mdp.txt"

[switch] $IgnoreHostKey = $false

for ($i = 0; $i -le $srv.count-1; $i++){
write-host "etape 1" $srv[$i]
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = $srv[$i]
$sessionOptions.UserName = "root"
$sessionOptions.Password = $mdp[$i]
$sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = $IgnoreHostKey
$session = New-Object WinSCP.Session
write-host "etape 2" $srv[$i]
try
{
$session.Open($sessionOptions)
$session.GetFiles("/home/gconf/*.gz", "C:\Users\adm-l2b-jherve\test\*").check()
write-host "etape 3 Ligne $i correspondant" $srv[$i]
write-host "================="
}

finally
{
# Disconnect, clean up
$session.Dispose()
}
}
martin

I do not know PowerShell good enough. Consider asking on stackoverflow.com. Post a link here if you do.
rvjhon

Thanks prikryl for your help,

would do you help me for this script ?

regards
martin

Re: two ask for powershell script

rvjhon wrote:

Can i use WinSCPnet.dll whitout $sessionOptions.SshHostKeyFingerprint ?

If you do not care about security you can use SessionOptions.GiveUpSecurityAndAcceptAnySshHostKey.

And can i read on a file HostName and password ... ?

Do you mean if you can read hostname and password from a file? WinSCP .NET assembly cannot do this directly, but implementing this in PowerShell should be pretty easy. That's out of scope of the forum though.
rvjhon

two ask for powershell script

Hi,

I want use a Powershell script for download file on few serveur (20-30).
Can i use WinSCPnet.dll whitout $sessionOptions.SshHostKeyFingerprint ?
And can i read on a file HostName and password ... ?

I have test a many solution with Get-Content and Foreach-Object.
and now i have no idea for creating this script

Thanks so much
King Regards
Jhon

My script:

try
{
[Reflection.Assembly]::LoadFrom("WinSCPnet.dll") | Out-Null
ForEach ($liste_srv in Get-Content "z:\projet_enable\liste_serveur.txt")
($liste_mdp in Get-Content "z:\projet_enable\liste_mdp.txt")
($liste_ssh in Get-Content "z:\projet_enable\liste_ssh.txt")
}
{

$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = $liste_srv
$sessionOptions.UserName = "root"
$sessionOptions.Password = $liste_mdp
$sessionOptions.SshHostKeyFingerprint = $liste_ssh
$session = New-Object WinSCP.Session
try
{
$session.Open($sessionOptions)
$session.GetFiles("/home/gconf/*.gz", "C:\Users\adm-l2b-jherve\test\*").check()
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
exit 0
}

catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}



ForEach ($system in Get-Content "liste_serveur.txt")
{
Write-Host $system
Write-Host " "
}
exit 1