Hello, ps1
Pls:
How add the SFTP protocole?
The scripte:
$Xftp = “…”
$XlocalDirectory = “c:.…”
$Xuser = “…”
$Xpass = '1…"
$Xwebclient = New-Object System.Net.WebClient
$Xwebclient.Credentials = New-Object System.Net.NetworkCredential($Xuser,$Xpass)
$XFiles = Get-ChildItem -Path “c:.…*” -Rec -For | ? {$.LastWriteTime -gt (Get-Date).AddHours(-1)} | where { ! $.PSIsContainer } | Select-Object FullName
$Xnombre = $XFiles.Count
foreach ($XFile in $XFiles)
{
$XLocalFile = $XFile.FullName
…
Tnk for your help
Arnold
Hi Arnold-ps1, welcome to the forum.
You’ll need to provide additional information. What does this mean exactly? Also, what does the random script have to do with the question?
Hello Sir
tnx
The protocole start before the section before scripte? Non?
My scripte works! But i need also the SFTP protocole
Arnold
Maybe you can advise what you are trying to do so we can discern what you are needing? If you are asking how to run commands against an SFTP server, install a module that provides that functionality. You can search the PSGallery with
Find-Module *sftp*
When I need to run powershell commands against SFTP servers I like to use the WinSCP library
Hello # krzydoug
Thnx for your reply! I no WinSCP !: the probleme is so, i can only update one serveur… With my scripte I connecte at the divers serveur a the same time !
Arnold
Hello Sir
I get it !
My attemption is: But is not work
Install-Module -Name WinSCP # (PowerShell ver 7) okay
Get-Module winscp | ft Path # ???
$WinSCPSessionOption = New-WinSCPSessionOption -HostName 192.168.5.150 -Protocol Scp -PortNumber 222 -Credential (Get-Credential) # how us it ???
$sshHostKeyFingerprint = Get-WinSCPHostKeyFingerprint -SessionOption $WinSCPSessionOption -Algorithm SHA-256
$WinSCPSessionOption.SshHostKeyFingerprint = $sshHostKeyFingerprint
$WinSCPSessionOption.PortNumber = 21
$WinSCPSession = New-WinSCPSession -SessionOption ($WinSCPSessionOption)
Get-WinSCPSession # ???
download
Get-WinSCPChildItem -WinSCPSession $WinSCPSession -Path .
Send-WinSCPItem -WinSCPSession $WinSCPSession -Path "C:\temp*." -Destination “/studio/”
Test-WinSCPPath -WinSCPSession $WinSCPSession -Path /studio/.*
Remove-WinSCPSession
This is the way
type or paste code here
cls
Get-Module winscp | ft Path
$hostname = ‘ftp://…’
$username = ‘…’
$password = ‘…’
$PortNumber = “21”
$WinSCPSessionOption = New-WinSCPSessionOption -Property @{
Protocol = [WinSCP.Protocol]::FTP # Transfer Protocols (SFTP, FTP, SCP, WebDAV, S3)
HostName = $using:hostname
UserName = $using:username
SecurePassword = $using:password
PortNumber = $using:PortNumber
}
$sshHostKeyFingerprint = Get-WinSCPHostKeyFingerprint -SessionOption $WinSCPSessionOption -Algorithm SHA-256
$WinSCPSessionOption.SshHostKeyFingerprint = $sshHostKeyFingerprint
$WinSCPSession = New-WinSCPSession -SessionOption ($WinSCPSessionOption)
Get-WinSCPSession
Receive-WinSCPItem -WinSCPSession $WinSCPSession -RemotePath “/” -LocalPath “C:\Users\admin\OneDrive.…”
$WinSCPSessionOption.SshHostKeyFingerprint = $sshHostKeyFingerprint
Remove-WinSCPSession
type or paste code here
You can close tis session. Thx
Sir, like so ?
Thanks for sharing. Could you please format your code as code? Use the preformatted option (the </> icon) If you don’t see it check under the settings wheel.
How us it
First : You have to Install the module:
Install-Module -Name WinSCP (only one time !)
=======================================
Seconde: Start Your scripte with
$help = Get-Module winscp | ft Path
$help.GetType()
get command :: WinSCP
=======================================
Thirdly times:
Add all information in the protocole status (Sessions)
Also the chiffrement: non (is standart), SSL/Tls implicite, Tls/SSL explicite
========================================
Start all ligne so with yours new parameter: Protocole [WinSCP.Protocol]:: …
========================================
My exempts is to upload files. Thats all to do !
Arnold