{"id":3628,"date":"2026-01-14T15:59:10","date_gmt":"2026-01-14T21:59:10","guid":{"rendered":"https:\/\/microsoftgeek.com\/?p=3628"},"modified":"2026-01-14T15:59:10","modified_gmt":"2026-01-14T21:59:10","slug":"simple-way-to-connect-to-ftps-and-sftp-using-powershell","status":"publish","type":"post","link":"https:\/\/microsoftgeek.com\/?p=3628","title":{"rendered":"Simple way to connect to FTPS and SFTP using PowerShell"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">&#x1f4a1; Multiple ways to connect to FTP\/FTPS server using PowerShell<\/h3>\n\n\n\n<p>To connect and list files on FTP server all you have to do is run 3 line of code<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Anonymous login\n$Client = Connect-FTP -Server 'speedtest.tele2.net' -Verbose\n$List = Get-FTPList -Client $Client\n$List | Format-Table\nDisconnect-FTP -Client $Client<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/evotec.xyz\/wp-content\/uploads\/2021\/08\/img_612a5af3a1897.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"xNdtLjn\"><a href=\"https:\/\/evotec.xyz\/wp-content\/uploads\/2021\/08\/img_612a5af3a1897.png\"><\/a><\/p>\n\n\n\n<p>If you would like to use username and password (most of the cases)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Login via UserName\/Password<br>$Client = Connect-FTP -Server 'test.rebex.net' -Verbose -Username 'demo' -Password 'password'<br>$List = Get-FTPList -Client $Client<br>$List | Format-Table<br>Disconnect-FTP -Client $Client<br><\/pre>\n\n\n\n<p>And finally, the same thing can be achieved using credentials that are a bit safer if you want to store the password instead of using the ClearText option safely.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Login via credentials<br>$Credential = Get-Credential -UserName 'demo' -Message 'Please enter password' # password is password<br>$Client = Connect-FTP -Server 'test.rebex.net' -Verbose -Credential $Credential<br>$List = Get-FTPList -Client $Client<br>$List | Format-Table<br>Disconnect-FTP -Client $Client<br><\/pre>\n\n\n\n<p><strong>Connect-FTP<\/strong>&nbsp;cmdlet will use default settings when connecting to a given FTP server. Of course, you can define what settings you want to use.&nbsp; All the options such as&nbsp;<strong>SSL<\/strong>,&nbsp;<strong>Data Connection Type<\/strong>,&nbsp;<strong>Encryption Modes<\/strong>,&nbsp;<strong>validation of certificates<\/strong>&nbsp;are there.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">NAME<br>    Connect-FTP<br><br>SYNTAX<br>    Connect-FTP [-Server ] [-Credential ] [-EncryptionMode {None | Implicit | Explicit | Auto}] [-DataConnectionType {AutoPassive | PASV | PASVEX | EPSV | AutoActive | PORT | EPRT}] [-SslBuffering {Auto | Off | On}] [-DisableDataConnec<br>    tionEncryption] [-DisableValidateCertificateRevocation] [-ValidateAnyCertificate] [-Port ] [-SendHost] [-SocketKeepAlive] [-AutoConnect]  []<br><br>    Connect-FTP [-FtpProfile ]  []<br><br>    Connect-FTP [-Server ] [-Username ] [-Password ] [-EncryptionMode {None | Implicit | Explicit | Auto}] [-DataConnectionType {AutoPassive | PASV | PASVEX | EPSV | AutoActive | PORT | EPRT}] [-SslBuffering {Auto | Off | On}] [-Disa<br>    bleDataConnectionEncryption] [-DisableValidateCertificateRevocation] [-ValidateAnyCertificate] [-Port ] [-SendHost] [-SocketKeepAlive] [-AutoConnect]  []<br><br><br>ALIASES<br>    None<br><br><br>REMARKS<br>    None<br><\/pre>\n\n\n\n<p>It&#8217;s also possible to run\u00a0<strong>Request-FTPConfiguration<\/strong>\u00a0and have the module test for you all different combinations that work with a given FTP server.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Login via UserName\/Password<br>$ProfileFtp1 = Request-FTPConfiguration -Server 'test.rebex.net' -Verbose -Username 'demo' -Password 'password'<br>$ProfileFtp1 | Format-Table<br><br># Anonymous login<br>$ProfileFtp2 = Request-FTPConfiguration -Server 'speedtest.tele2.net' -Verbose<br>$ProfileFtp2 | Format-Table<br><\/pre>\n\n\n\n<p>Profiles from&nbsp;<strong>Request-FTPConfiguration<\/strong>&nbsp;can then be directly used by the&nbsp;<strong>Connect-FTP<\/strong>&nbsp;cmdlet.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><br># Login via UserName\/Password via autodetect - keep in mind using Connect-FTP directly will be faster...<br>$ProfileFtp1 = Request-FTPConfiguration -Server 'test.rebex.net' -Verbose -Username 'demo' -Password 'password'<br>$ProfileFtp1 | Format-Table<br><br># use first profile<br>$Client = Connect-FTP -FtpProfile $ProfileFtp1[0]<br>Get-FTPList -Client $Client | Format-Table<br>Disconnect-FTP -Client $Client<br><\/pre>\n\n\n\n<p>Or you can simply use the&nbsp;<strong>AutoConnect<\/strong>&nbsp;switch, which will go thru those options directly before connecting.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Login via UserName\/Password via autoconnect - this will try all options and connect, while displaying Verbose what settings were used to achieve connection<br># Useful for trying out every possible combination<br>$Client = Connect-FTP -Server 'test.rebex.net' -Username 'demo' -Password 'password' -AutoConnect -Verbose<br>Get-FTPList -Client $Client | Format-Table<br>Disconnect-FTP -Client $Client<br><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">&#x1f4a1; Uploading \/ Downloading FTP files from FTP\/FTPS server using PowerShell<\/h3>\n\n\n\n<p>Now that you know how to connect to an&nbsp;<strong>FTP<\/strong>&nbsp;server let&#8217;s check how you can upload some files to the&nbsp;<strong>FTP<\/strong>&nbsp;server. As you can see below, I&#8217;m first connecting to the&nbsp;<strong>FTP<\/strong>&nbsp;server, then listing current files and checking the content, then checking the directory&#8217;s content within the&nbsp;<strong>FTP<\/strong>&nbsp;server. Finally, I get a list of files stored locally and upload them one by one into the&nbsp;<strong>FTP<\/strong>&nbsp;server by using the&nbsp;<strong>Send-FTPFile<\/strong>&nbsp;cmdlet. You can either use this command to send file by file, including auto-creation of the remote directory or upload all files at once.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$Client = Connect-FTP -Server '192.168.241.187' -Verbose -Username 'test' -Password 'BiPassword90A' -EncryptionMode Explicit -ValidateAnyCertificate<br># List files<br>$List = Get-FTPList -Client $Client<br>$List | Format-Table<br># List files within Temporary directory<br>$List = Get-FTPList -Client $Client -Path '\/Temporary'<br>$List | Format-Table<br><br># Get local files<br>$ListFiles = Get-ChildItem -LiteralPath $PSScriptRoot\\Upload<br><br># Upload file by file<br>foreach ($File in $ListFiles) {<br>    # To temporary<br>    Send-FTPFile -Client $Client -LocalPath $File.FullName -RemotePath \"\/Temporary\/$($File.Name)\" -RemoteExists Overwrite<br>    # to directory within Temporary that may not exists<br>    Send-FTPFile -Client $Client -LocalPath $File.FullName -RemotePath \"\/Temporary\/CreateDir\/$($File.Name)\" -RemoteExists Skip -CreateRemoteDirectory<br>}<br><br># Upload all files at once to FTP<br>Send-FTPFile -Client $Client -LocalPath $ListFiles.FullName -RemotePath \"\/Temporary\" -RemoteExists Overwrite<br><br>Disconnect-FTP -Client $Client<br><\/pre>\n\n\n\n<p>Similarly, if you want to download files from an&nbsp;<strong>FTP<\/strong>&nbsp;server, you would connect to&nbsp;<strong>FTP<\/strong>, get a list of files on&nbsp;<strong>FTP<\/strong>, find the files you need, and download those files \u2013 all of that in less than 10 lines of code.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Connect to FTP<br>$Client = Connect-FTP -Server 'test.rebex.net' -Verbose -Username 'demo' -Password 'password'<br><br># Get list of files on FTP<br>$List = Get-FTPList -Client $Client -Path '\/pub\/example'<br><br># Find latest file on FTP server<br>$FindLatestFile = $List | Where-Object { $_.Type -eq 'File' } | Sort-Object -Property Modified -Descending | Select-Object -First 2<br><br># Download that file<br>foreach ($RemoteFile in $FindLatestFile) {<br>    Receive-FTPFile -Client $Client -RemoteFile $RemoteFile -LocalPath \"$PSScriptRoot\\Download\\$($RemoteFile.Name)\" -LocalExists Overwrite -VerifyOptions Retry, None<br>}<br># Download multiple files into directory<br>Receive-FTPFile -Client $Client -RemoteFile $FindLatestFile -LocalPath \"$PSScriptRoot\\Download\" -LocalExists Overwrite -VerifyOptions Retry, None<br><br># Disconnect<br>Disconnect-FTP -Client $Client<br><\/pre>\n\n\n\n<p>Of course, uploading and downloading files from an&nbsp;<strong>FTP<\/strong>&nbsp;server using&nbsp;<strong>PowerShell<\/strong>&nbsp;is not the only thing you can do on an&nbsp;<strong>FTP server<\/strong>. You may want to get or set permissions, or for example, if something is not working correctly, you may want to see what&#8217;s happening behind the scenes and look at what the&nbsp;<strong>FTP<\/strong>&nbsp;server is reporting.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># If you want to track responses from FTP<br>Set-FTPTracing -Enable -DisplayConsole<br><br>$Client = Connect-FTP -Server '192.168.241.187' -Verbose -Username 'test' -Password 'BiPassword90A' -EncryptionMode Explicit -ValidateAnyCertificate<br># List files<br>Get-FTPList -Client $Client -Path '\/Temporary' | Format-Table *<br>Get-FTPChmod -Client $Client -RemotePath '\/Temporary'<br><br># Set \/ Read Chmod - you need to have permissions for this to work properly<br>Set-FTPChmod -Client $Client -RemotePath '\/Temporary\/OrgChart (1).pdf' -Permissions 666<br>Set-FTPChmod -Client $Client -RemotePath '\/Temporary\/CreateDir' -Permissions 666<br><br># Set \/ Read Chmod - you need to have permissions for this to work properly<br>Get-FTPChmod -Client $Client -RemotePath '\/Temporary\/OrgChart (1).pdf'<br>Get-FTPChmod -Client $Client -RemotePath '\/Temporary\/CreateDir'<br><br>Set-FTPTracing -Disable<br><\/pre>\n\n\n\n<p>Using&nbsp;<strong>Set-FTPTracing<\/strong>&nbsp;to enable or disable visibility of commands being sent to the FTP server can be very useful to track what is actually happening behind the scenes. If you want to get current permissions of a file or folder, you will use&nbsp;<strong>Get-FTPChmod<\/strong>&nbsp;to set permissions&nbsp;<strong>Set-FTPChmod<\/strong>. Of course \u2013 to change something, you may need to have permissions first. Finally, if you would like to test if the file exists on the source, you can do this using<strong>&nbsp;the Test-FTPFile<\/strong>&nbsp;command.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$Client = Connect-FTP -Server '192.168.241.187' -Verbose -Username 'test' -Password 'BiPassword90A' -EncryptionMode Explicit -ValidateAnyCertificate<br># List files<br>Test-FTPFile -Client $Client -RemotePath '\/Temporary'<br><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">&#x1f4a1; Other FTP\/FTPS commands<\/h3>\n\n\n\n<p>Of course, there are many other things you can do on an FTP server. I&#8217;ve created cmdlets to move FTP file (<strong>Move-FTPFile<\/strong>), move&nbsp;<strong>FTP<\/strong>&nbsp;directory (<strong>Move-FTPDirectory<\/strong>), remove files or folders (<strong>Remove-FTPDirectory<\/strong>\/<strong>Remove-FTPFile<\/strong>), and it&#8217;s all mostly self-explanatory. But one thing that could be useful if your FTP server supports it \u2013 is FXP transfer. FXP transfer is basically a way to transfer files between two FTP servers without utilizing your machine at all. You tell one FTP server that it should connect to the other FTP server and transfer the files without being involved. This allows you to send files without storing them locally on your own machine. You would use&nbsp;<strong>Start-FXPFileTransfer<\/strong>&nbsp;or&nbsp;<strong>Start-FXPDirectoryTransfer<\/strong>&nbsp;commands. But to tell you the truth, I&#8217;ve not tested if they work \u2013 as my servers \u2013 don&#8217;t support it.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&#x1f4a1; Connecting to SFTP server using PowerShell<\/h3>\n\n\n\n<p>Similar code can be used for SFTP protocol. Connecting to SFTP, listing SFTP files\/folders is just three lines of code.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$SftpClient = Connect-SFTP -Server '192.168.240.29' -Username 'przemek' -Password 'YourPassword'\nGet-SFTPList -SftpClient $SftpClient | Format-Table\nGet-SFTPList -SftpClient $SftpClient -Path \"\/home\" | Format-Table\nDisconnect-SFTP -SftpClient $SftpClient<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/evotec.xyz\/wp-content\/uploads\/2021\/08\/img_612a5aa8ca718.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"VlVxNQM\"><a href=\"https:\/\/evotec.xyz\/wp-content\/uploads\/2021\/08\/img_612a5aa8ca718.png\"><\/a><\/p>\n\n\n\n<p>Since&nbsp;<strong>SFTP<\/strong>&nbsp;is based on&nbsp;<strong>SSH<\/strong>, there&#8217;s much less option to play with for&nbsp;<strong>Connect-SFTP<\/strong>&nbsp;configuration. Uploading files is as easy as using one line of code.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$SftpClient = Connect-SFTP -Server '192.168.241.187' -Verbose -Username 'test' -Password 'BiPassword90A'<br>Get-SFTPList -SftpClient $SftpClient | Format-Table<br>Get-SFTPList -SftpClient $SftpClient -Path \"\/Temporary\" | Format-Table *<br><br>$ListFiles = Get-ChildItem -LiteralPath $PSScriptRoot\\Upload<br>foreach ($File in $ListFiles) {<br>    Send-SFTPFile -SftpClient $SftpClient -LocalPath $File.FullName -RemotePath \"\/Temporary\/$($File.Name)\" -AllowOverride<br>}<br><br>Disconnect-SFTP -SftpClient $SftpClient<br><\/pre>\n\n\n\n<p>Similarly, as you used the code above (<strong>Send-SFTPFile<\/strong>) to upload files, you can also download files from&nbsp;<strong>SFTP<\/strong>&nbsp;using&nbsp;<strong>Receive-SFTPFile<\/strong>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$SftpClient = Connect-SFTP -Server '192.168.240.29' -Username 'przemek' -Password 'BigMouth88nA!!A00!A'<br>Get-SFTPList -SftpClient $SftpClient | Format-Table<br>Get-SFTPList -SftpClient $SftpClient -Path \"\/home\" | Format-Table<br>Receive-SFTPFile -SftpClient $SftpClient -RemotePath '\/home\/przemek\/test1.txt' -LocalPath \"$PSScriptRoot\\Downloads\\mmm.txt\"<br>Send-SFTPFile -SftpClient $SftpClient -LocalPath \"$PSScriptRoot\\Downloads\\mmm.txt\" -RemotePath '\/home\/przemek\/mmm.txt' -AllowOverride<br><\/pre>\n\n\n\n<p>You can connect, list, upload, download, and disconnect from the SFTP server with just five commands.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&#x1f4a1; Executing SSH commands from PowerShell<\/h3>\n\n\n\n<p>If that&#8217;s not enough, you can always connect directly to SSH and execute commands that can help with additional automation steps that can&#8217;t be done using transfer protocol.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$SshClient = Connect-SSH -Server '192.168.240.29' -Username 'przemek' -Password 'sdsd'<br><br>$Command = {<br>    'cd \/'<br>    'ls -la'<br>    'cd \/etc'<br>    'ls -la'<br>}<br>$SshCommand = Send-SSHCommand -SSHClient $SshClient -Command $Command -Verbose<br>$SshCommand<br><br><br>$Command = {<br>    'cat \/etc\/hosts.allow'<br>}<br>$SshCommand = Send-SSHCommand -SSHClient $SshClient -Command $Command -Verbose<br>$SshCommand<br><\/pre>\n\n\n\n<p>While I have not spent a lot of time on this functionality, it does add some fun to this module.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x1f4a1; Multiple ways to connect to FTP\/FTPS server using PowerShell To connect and list files on FTP server all you have to do is run 3 line of code # Anonymous login $Client = Connect-FTP -Server &#8216;speedtest.tele2.net&#8217; -Verbose $List = Get-FTPList -Client $Client $List | Format-Table Disconnect-FTP -Client $Client If you would like to use [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,59],"tags":[],"class_list":["post-3628","post","type-post","status-publish","format-standard","hentry","category-computer-tech-stuff","category-powershell"],"_links":{"self":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3628"}],"version-history":[{"count":1,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3628\/revisions"}],"predecessor-version":[{"id":3629,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3628\/revisions\/3629"}],"wp:attachment":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}