<!--
  canonical-url: https://www.avonture.be/blog/php-grep-searching-at-lightning-speed
  published:     2025-01-19
  This is a static plain-Markdown mirror generated at build time.
  Visit the canonical URL above for the fully rendered page, with images and interactive components.
-->

# Search your FTP server at lightning speed

> Tired of painfully slow FTP search functions? Discover php_grep, the ultra-fast PHP script that uses regular expressions to find content on your FTP server at lightning speed.

---
![Search your FTP server at lightning speed](/img/v2/winscp.webp)

**TL;DR**

Searching for text on an FTP server can be incredibly slow, especially with tools like WinSCP's built-in search. This article introduces `php_grep`, a lightweight and ultra-fast PHP script that revolutionizes FTP searching. By simply uploading this single file to your server and accessing it via a URL, you can perform lightning-fast, regular-expression-based searches for content within your files, and even filter results by file type.

Did you know that using [WinSCP](https://winscp.net/), you can run a search on your FTP to find all the documents containing a given string? It's native in WinSCP; nothing more to install but...

*Other WinSCP tricks on this blog: [download files with a specific extension recursively](/blog/winscp-download-recursively-files) and [synchronize host and remote](/blog/winscp-synchronize-both).*

However, it's insanely slow; let's see how we can do it better and almost instantaneous.

## WinSCP - Search for Text

Probably you never had noticed (it was my case), you can start searching files on your FTP server using WinSCP.

To do this, go to the `Commands` menu, then `Static custom` commands and finally `Search for Text...`.  Type your search pattern and press `Enter`.

![Search for Text](./images/search_for_text.webp)

A new Powershell prompt will be started and you'll see the list of scanned files.

![Result](./images/result.webp)

> **It's a Powershell script:**
>
> WinSCP will, in fact, start a `.ps1` script located here: `C:\Program Files (x86)\WinSCP\Extensions\SearchText.WinSCPextension.ps1`. Feel free to update the file to match your needs.

It's terribly slow and you'll get a huge list with all your files; not only the ones where the search pattern is retrieved. This function has the merit of existing, but it's not much.

## php\_grep

Time flies... In 2016, I developed an ultra-fast little script called [php\_grep](https://github.com/cavo789/php_grep) that scans every file present and, using a small regular expression, finds the files containing the search pattern and displays its location if the search is successful.

You just need to download a copy of my script (a single PHP page), copy the script on your FTP server and access it using a URL. Really easy.

This done, you'll get an interface where you can type, for sure, the search expression but also restricts the search to f.i. `.html` files.

![php\_grep in action](./images/php_grep.webp)

More info on <https://github.com/cavo789/php_grep>

*The trick here is to search **on the server**, so nothing has to travel over the wire. When the files are already on your own disk, the same "lightning speed" feeling is provided by [ripgrep](/blog/ripgrep).*
