Topic "two ask for powershell script"

Author Message
rvjhon

Guest


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
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
rvjhon wrote:
Can i use WinSCPnet.dll whitout $sessionOptions.SshHostKeyFingerprint ?

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

Quote:
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.
_________________
Martin Prikryl
rvjhon

Guest


Thanks prikryl for your help,

would do you help me for this script ?

regards
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
I do not know PowerShell good enough. Consider asking on stackoverflow.com. Post a link here if you do.
_________________
Martin Prikryl
rvjhon

Guest


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
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
You have to set it to "true", not "false".
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License