From the course: Learning Static Site Building with Hugo

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Remove old files from the server

Remove old files from the server

From the course: Learning Static Site Building with Hugo

Start my 1-month free trial

Remove old files from the server

- [Instructor] In most cases, you'll want to remove or clean out your old site files before uploading newly generated files. Without this step, anything you delete on the Hugo side would stay on your server until you go manually delete it. If you only plan on adding content and never removing anything, you could skip this step. I'm going to add some code to the cleanRemote method. What I'll do is I'm going to need to call SFTP client to list the files that are currently on the server. I'll do return sftp .list. We'll tell it to list the remotePathBase, essentially, the public HTML folder. And then after that, we'll do then. We'll get back a list of objects, and we want to act on those objects, so we'll say objectList to a new block of code. There are a few items we'll want to always ignore, so let's filter those out. Let's say objectList equals objectList.filter and anything that is not part of something we'll call ingoredRemoteItems.has obj .name. And that'll match against anything…

Contents