Seth Buesing
Seth Buesing

Reputation: 11

Synchronizing a local file with a remote web host

I have a pdf that I want to fetch whenever my computer is connected to the internet such that any time there is a new version uploaded, I replace the local copy on my device. How can I accomplish this for a file hosted on an arbitrary website, for example https://lorempdf.com/140/85/1 (generic pdf generator, fetches new pdf upon load request). Ideally to not waste resources, I would like this to occur only at some scheduled time/event (upon opening the pdf locally or periodically, or upon reconnecting to the internet).

A further question is regarding how one might be able to do this on an authenticated website. One of my desired files requires a login to access.

Any help is much appreciated.

My attempts thus far:

I've cobbled together a powershell script that I run whenever I want to open the pdf

Invoke-WebRequest -Uri https://lorempdf.com/140/85/1 -OutFile C:\Users\...\source\test.pdf
C:\Users\...\source\test.pdf

Which in the first line fetches the most recent copy from the webpage, and the second line opens my desired file.

This works alright for unauthenticated access, and it's certainly not elegant. The pdf is always opened in my default pdf viewer (web browser) which I would like to have the flexibility to change. Of course, I can just update the file, close the pdf viewer and open the source file with a new program but again this is not very elegant, and if such a solution exists to schedule updates every time I attempt to open the file itself, or synchronizing periodically that would be much more satisfactory.

Again, the pdf I would ultimately like to access is blocked behind authentication. When I try to fetch it using the above script the pdf returned is unreadable, presumably because my machine was unable to authenticate to reach my desired remote pdf. In particular, the website authentication is facilitated by Shibboleth. Using the -Credential parameter for Invoke-WebRequest has been suggested but does not seem to properly feed into Shibboleth (which makes sense). Furthermore, when normally accessing this file, if not logged in on my browser already I will be redirected to the Shibboleth login, which when satisfied will take me to a home page, but if my login is current on my browser then I am taken directly to the desired file.

Upvotes: 1

Views: 24

Answers (0)

Related Questions