# Ftp; add protocole SFTP

**URL:** <https://forums.powershell.org/t/ftp-add-protocole-sftp/22630>\
**Category:** PowerShell Help\
**Created:** [July 19, 2023, 1:52pm UTC](https://forums.powershell.org/t/ftp-add-protocole-sftp/22630 "2023-07-19T13:52:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arnold-ps1](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Arnold-ps1](https://forums.powershell.org/u/Arnold-ps1)\
**Post date:** [July 19, 2023, 1:52pm UTC](https://forums.powershell.org/t/ftp-add-protocole-sftp/22630/1 "2023-07-19T13:52:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [July 19, 2023, 3:53pm UTC](https://forums.powershell.org/t/ftp-add-protocole-sftp/22630/2 "2023-07-19T15:53:35Z")

</div>

Hi Arnold-ps1, welcome to the forum.

> [@Arnold-ps1](#):
>
> How add the SFTP protocole?

You’ll need to provide additional information. What does this mean exactly? Also, what does the random script have to do with the question?

---

<div class="post-metadata">

**Author:** ![Arnold-ps1](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Arnold-ps1](https://forums.powershell.org/u/Arnold-ps1)\
**Post date:** [July 19, 2023, 3:58pm UTC](https://forums.powershell.org/t/ftp-add-protocole-sftp/22630/3 "2023-07-19T15:58:50Z")

</div>

Hello Sir  
tnx

The protocole start before the section before scripte? Non?  
My scripte works! But i need also the SFTP protocole

Arnold

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [July 19, 2023, 4:03pm UTC](https://forums.powershell.org/t/ftp-add-protocole-sftp/22630/4 "2023-07-19T16:03:36Z")

</div>

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

```auto
Find-Module *sftp*

```

When I need to run powershell commands against SFTP servers I like to use the WinSCP library

> **[Using WinSCP .NET Assembly from PowerShell :: WinSCP](https://winscp.net/eng/docs/library_powershell)**
>
> WinSCP is a free file manager for Windows supporting FTP, SFTP, S3 and WebDAV.

---

<div class="post-metadata">

**Author:** ![Arnold-ps1](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Arnold-ps1](https://forums.powershell.org/u/Arnold-ps1)\
**Post date:** [July 19, 2023, 4:18pm UTC](https://forums.powershell.org/t/ftp-add-protocole-sftp/22630/5 "2023-07-19T16:18:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Arnold-ps1](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Arnold-ps1](https://forums.powershell.org/u/Arnold-ps1)\
**Post date:** [July 20, 2023, 8:22am UTC](https://forums.powershell.org/t/ftp-add-protocole-sftp/22630/6 "2023-07-20T08:22:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Arnold-ps1](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Arnold-ps1](https://forums.powershell.org/u/Arnold-ps1)\
**Post date:** [July 28, 2023, 9:10am UTC](https://forums.powershell.org/t/ftp-add-protocole-sftp/22630/7 "2023-07-28T09:10:37Z")

</div>

This is the way 🙂

```auto
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

```auto
type or paste code here

```

You can close tis session. Thx

Sir, like so ?

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [July 28, 2023, 4:11pm UTC](https://forums.powershell.org/t/ftp-add-protocole-sftp/22630/8 "2023-07-28T16:11:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Arnold-ps1](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Arnold-ps1](https://forums.powershell.org/u/Arnold-ps1)\
**Post date:** [July 31, 2023, 5:07am UTC](https://forums.powershell.org/t/ftp-add-protocole-sftp/22630/9 "2023-07-31T05:07:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:14pm UTC](https://forums.powershell.org/t/ftp-add-protocole-sftp/22630/10 "2024-05-16T20:14:44Z")

</div>

Closed on May 16, 2024, 8:14pm UTC


