Skip to content

Add tail toggle button to toolbar - #421

Open
MahdiHamidpour wants to merge 2 commits into
ashkulz:masterfrom
MahdiHamidpour:feature/tail
Open

MahdiHamidpour wants to merge 2 commits into
ashkulz:masterfrom
MahdiHamidpour:feature/tail

Conversation

@MahdiHamidpour

@MahdiHamidpour MahdiHamidpour commented Nov 23, 2026 •

Copy link
Copy Markdown

Add tail (follow remote file) feature

Closes #330

This adds a "Follow remote file (tail)" toggle to the NppFTP toolbar. When it is enabled for the selected remote file, NppFTP keeps the local copy in sync with the server, similar to tail -f.

How it works

  1. On enable, the file is downloaded once (binary mode) into the cache and opened in Notepad++.
  2. Every 2 seconds the remote size is checked. If the file grew, only the new bytes are fetched and appended to the cached file.
  3. The document is reloaded silently and, if it is the active document, scrolled to the end.
  4. If the remote file became smaller (truncated or rotated), it is downloaded again from the start.

Changes

  • Toolbar: new check-style button with its own icon (toolbar_tail.bmp, 16x16, 8-bit, same style as the existing icons). It is enabled when a file is selected, and stays enabled while tailing so it can always be switched off.
  • FTPClientWrapper: two new methods, implemented for both backends:
    • GetRemoteSize(): SIZE for FTP/FTPS, sftp_stat for SFTP
    • ReceiveFileFrom(offset): REST + RETR (through UTCP's ResumeReceiveFile and a new AppendHandleDataSource) for FTP/FTPS, sftp_seek64 + sftp_read for SFTP
  • QueueTail: new operation on the transfer queue. It always uses binary mode so local and remote offsets match.
  • FTPWindow: tail session handling (start/stop/poll on a WM_TIMER). Results of a stopped session are ignored. Tailing stops on disconnect, on error, or when the window is destroyed.
  • Save protection: saving the file that is being followed does not upload it. Otherwise the remote log would be overwritten with an outdated copy.

Known limitations

  • Files larger than 2 GB are not supported (UTCP uses long for sizes/offsets).
  • A rotation is not detected if the new file is already larger than the previous offset at the next poll.
  • Each update reloads the whole document in Notepad++, which may be slow for very large logs.
  • The poll interval is fixed at 2 seconds. It could be made configurable in the settings later.
  • If Notepad++ file status auto-detection is set to prompt, a "file modified" prompt may occasionally appear.

Testing

  • FTP: append lines on the server (echo test >> file.log) and check they appear
  • FTPS
  • SFTP
  • Truncate the file (> file.log) and check it is reloaded from the start
  • Disconnect while tailing and check the button is switched off
  • Save the tailed file and check it is not uploaded

Add a check-style "Follow remote file (tail)" button to the plugin
toolbar as the first step towards issue ashkulz#330.

- New toolbar bitmap toolbar_tail.bmp (16x16, 8-bit, same style and
  background colour as the existing toolbar icons)
- New IDs IDB_BITMAP_TAIL (118) and IDB_BUTTON_TOOLBAR_TAIL (510)
- Button is enabled only while connected and a file is selected
- Toggling stores the state in FTPWindow::m_tailEnabled
- State is reset when the session disconnects

The polling/append logic itself will follow in a separate commit.
When the toolbar tail button is enabled for the selected remote file,
NppFTP downloads it once into the cache, opens it in Notepad++ and then
polls the server every 2 seconds, fetching only the bytes added since
the previous poll.

- FTPClientWrapper: new GetRemoteSize() and ReceiveFileFrom(offset)
  - FTP/FTPS: SIZE, and REST + RETR via UTCP ResumeReceiveFile with a
    new AppendHandleDataSource
  - SFTP: sftp_stat, and sftp_seek64 + sftp_read
- New QueueTail operation on the transfer queue (always binary mode so
  local and remote offsets match). If the remote file becomes smaller
  (truncated or rotated) it is downloaded again from the start.
- FTPWindow: Start/Stop/PollTail driven by a WM_TIMER; new data is
  written to the cache file, the document is reloaded silently and
  scrolled to the end if it is the active one. Results of a stopped
  tail session are ignored (generation counter).
- Tail stops on disconnect, on error and when the plugin window is
  destroyed. The button stays enabled while tailing so it can always
  be switched off.
- Saving the followed file does not upload it, so the remote log
  cannot be overwritten with an outdated copy.
@MahdiHamidpour
MahdiHamidpour marked this pull request as ready for review November 23, 2026 14:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please add tail feature

1 participant