Fixed Knowledge Base

Get all the help you need here.

File Management

Posted 03rd October, 2018

Every website you view online is a collection of files and data. Your computer downloads those files (after doing a DNS lookup and interprets them through your web browser. What you see when you visit any website is essentially code translated into a readable format.

This guide explains how those files are structured, and then how they are stored and updated on web servers. When we make changes to a website, or when we back up a website, we need to access these files.

Contents

  • Files vs Databases
  • File structure
  • Uploading and Downloading Files
    • FTP
    • SSH/SFTP
    • Rsync

Files vs. Databases

Most websites consist of a selection of files, as well as a database. Databases usually contain the content of a page, whereas files contain the logic of how it should be displayed. For example:

  • Facebook.com will have a file that lays out a profile page, but the content for every profile will be stored in a database. That means only one file, but billions of profiles stored in the database.
  • This documentation system does not have individual pages for each guide. Instead, it has one page, with different content loaded from the database based on what the reader requests.
  • When you search Google.com the results are displayed dynamically from a database. The results page specifies the format and the layout of those results.
  • A basic static one page website, however, may just be a single file with no database attached.

Files are linked to the database with a configuration file. When we work on a website, or when we back up a website, we need access to both the files and the database.

You can read more on databases in this connected guide.

File Structure

Websites have a folder structure just like on your computer. For instance in most cases http://www.mywebsite.com/aboutus/mypage.html would be a file called mypage.html in a subfolder called aboutus.

This is a little over-simplified. With databases, or more advancing page routing, this is not necessarily the case. However, there is a still a hierarchy of levels of folder structure in any website, from Wordpress to Facebook.

Serverside vs. Clientside code

One important comment to make is that the raw contents of a file that exists on a server is not necessarily the content that is downloaded by a web visitor browsing the site. For example, the actual file might say:

$result = 2 + 2;
echo $result;

whereas the browser file would just show

4

The distinction here is that some code is serverside, and some is clientside. HTML and Javascript is usually client-side, whereas PHP or Python are serverside.

Uploading and Downloading Files

To upload or download files from your website, you need to connect and transfer files. This is also how the Fixed.net backup service takes a copy and restores websites. These use different protocols to connect.

FTP

FTP stands for File Transfer Protocol and is the default way to upload and download files from web servers. You require:

  • A hostname. This is the FDQN (or IP address) of the web server you want to connect to. Often this is ftp.yourdomain.com
  • A username and password to authenticate with.

These FTP credentials are usually provided by your web host on sign up. Alternatively you may have a control panel you can use to set them up.

You may also have a path to your files - this is the relative subfolder that your website runs from. For instance in a cPanel hosting environment, your path would be public_html.

In most cases it is preferable to use SSH/SFTP if available, as FTP is unencrypted.

Common Errors

  • Hostname does not resolve. You might seen an error like Connection Refused or Could not resolve hostname’ Perhaps your hostname has not cached yet, or there is no DNS record for it. Your host may provide another way of accessing the FTP host, or an IP address.
  • Password Incorrect. Ensure that your password is correct. Most providers will not let you view what it is, so you can request a reset.
  • Path Incorrect. The path you have set is not recognised. Try leaving it blank or putting a single /. This should take you to the root folder. Website files are often stored within the public_html folder, which might be entered as /public_html.
  • No files are seen. This is likely to be related to either path, or your FTP user's home folder could be a subfolder, rather than a higher level folder.
  • Permission Error.
  • TLS Error
  • Passive/Active mode errors

SSH/SFTP

Secure Shell (SSH) access is a secure way of connecting to, browsing, and transmitting to and from, a web server. Not only can files be moved, but more advanced commands can be run on a web server. Advanced users can connect using a terminal and working on the command line.

SFTP is a transfer protocol packaged with SSH that allows the transmission of files using SSH. It functions largely the same as FTP. To connect you require a hostname, a username and a password.

By default this will take the browser to the user’s default home directory. Therefore usually a path is required. Unlike with FTP, this path should be the full path to the folder, rather than the relative path.

RSYNC

Rsync is a way of syncing files between one server and another. It is a command that can be run from SSH. Rsync will only move files that have changed from one server to another, which makes it extremely efficient.

Categories:FTP