Blog | G5 Cyber Security

HTTPS vs SFTP: Secure File Transfers

TL;DR

Yes, HTTPS can be used for secure file transfers as an alternative to SFTP. However, it’s not a direct replacement and requires careful configuration. SFTP is generally simpler for dedicated file transfer, while HTTPS works well when integrating file transfer into web applications or existing websites.

Understanding the Differences

Both SFTP (Secure File Transfer Protocol) and HTTPS (Hypertext Transfer Protocol Secure) provide secure ways to move files between computers. They achieve this using encryption, but they do it differently:

Using HTTPS for File Transfers

Here’s how you can use HTTPS for secure file transfers:

  1. Enable TLS/SSL on your web server: This is the foundation of HTTPS. You’ll need an SSL certificate (Let’s Encrypt offers free certificates).
  2. Choose a method for transferring files: There are several options:
    • Direct Download Links: Create URLs that point directly to the file on your server. Accessing these links requires HTTPS.
      <a href="https://yourdomain.com/files/myfile.zip">Download My File</a>
    • POST Requests: Allow users to upload files through a web form using the POST method. Your server-side code will handle saving the uploaded file.

      Example (simplified PHP):

      if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $target_dir = "uploads/";
        $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
        move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
      }
    • REST APIs: Build a custom API endpoint for file uploads and downloads. This offers more control but requires more development effort.
  3. Implement Authentication & Authorisation: Control who can access or upload files.
    • Use standard web authentication methods (usernames/passwords, API keys).
    • Restrict access to specific directories based on user roles.
  4. Consider File Size Limits: Configure your web server and application to handle large file uploads appropriately.

SFTP Configuration (for comparison)

Setting up SFTP is usually simpler for dedicated file transfer:

  1. Enable SSH on your server: Most servers have SSH enabled by default.
  2. Configure SFTP access: Use a tool like sshd_config to specify which users can use SFTP and what directories they can access.
    Subsystem   sftp    /usr/lib/openssh/sftp-server
    Match User sftpuser
            ChrootDirectory /var/www/sftp
            ForceCommand internal-sftp
            AllowTcpForwarding no
            X11Forwarding no
  3. Use an SFTP client: Users can connect using software like FileZilla, WinSCP, or command-line tools.
    sftp sftpuser@yourdomain.com

HTTPS vs SFTP: Key Considerations

cyber security Best Practices

Exit mobile version