Tailing a File over FTP
I am attempting to access large log files on a remote server from my Windows desktop. I only have FTP access to this remote machine, not SSH access.
At the moment, I'm using WinSCP to pull the entire file down over FTP. This means I have to transfer the full file every time. However, given it's a log file I am likely to only need the last few lines.
This is particularly frustrating, as my bandwidth is severely limited, so transferring the entire file takes a few minutes.
If I had shell access this could easily be achieved by using something like tail -100
to obtain the last 100 lines.
I would like to find a solution to perform this via FTP. Note that it does not have to be a continuous tail, just a one-off would be sufficient.
Solution 1:
What you want to do, can definitely be done with FTP. Technically it's the same, what any FTP client does, when resuming an interrupted file download.
Though from a user perspective, I do not know, if any FTP client supports an explicit download of only given number of trailing bytes.
But some FTP clients will definitely allow you to download new trailing contents of file that you have previously downloaded.
Particularly with WinSCP, just initiate a log file download. Then, on the Overwrite confirmation prompt, select the Resume (it's in drop down menu of the No button). Note that the option is obviously available, only if the source file is larger than the destination file.
If you really want to download only the last few lines of the log, you can cheat WinSCP, by creating a dummy local file with a size bit smaller than the log file before you initiate download.
You can also easily automate the above trick:
fsutil file createnew mylog.log 100000000
winscp.com /command "open mysession" "get -resume /path_to_log/mylog.log" "exit"
For alternatives to the fsutil
, see Quickly create large file on a windows system?
With a more effort you can modify the script to first check log file size and automatically calculate dummy file size few kilobytes smaller than the log size.