What are FTP and SFTP? #
FTP (File Transfer Protocol) is a standard protocol for transferring files between two servers. However, FTP can be insecure if not properly encrypted. If you’re using one of our Managed VPS or our shared platform, your FTP connection will be encrypted and secure.
SFTP (SSH File Transfer Protocol or Secure File Transfer Protocol) is a different protocol that comes with SSH and works similarly to FTP but is always made over a secure connection. This connection can then be used to transfer files between servers and to traverse the filesystem on both servers.
When connecting to us, both protocols are secure, and you can use your protocol of choice. However, if you’re connecting to an unfamiliar system, SFTP is generally more secure.
Connecting Using SFTP #
Firstly, if you’re connecting to a package with us, you’ll need to unlock the FTP/SFTP on the package in question. It can be unlocked for either a period of time or for the IP address you’ll be connecting from. FTP/SFTP can be unlocked on the right-hand side of any package’s control panel.
Steps to Unlock FTP/SFTP:
- Log in to StackCP.
- Head to Manage Hosting and select the package you want SSH access for.
- Select SSH Access from under the Security section.
- Input the Public Key that was generated from PuTTYgen into the Public Key box, which will generate a handle for it. Then, select Add Public Key on the page.
- Save the private key locally under any name you want; you’ll need this later.
To Connect Using SFTP:
- Open your terminal or command prompt.
- Enter the following command:
$ sftp username@serverhostname
For example, if your domain is example.com:
$ sftp example.com@ftp.stackcp.com
If you are working on a custom SSH port (not the default port 22), you can open an SFTP session as follows:
$ sftp -oPort=custom_port username@serverhostname
Enter the password when prompted.
Once connected, your prompt will change to an SFTP one.
Navigating with SFTP
Check Current Directory:
sftp> pwd
Output: Remote working directory: /
List Directory Contents:
sftp> ls
Output:
examplefile1.txt examplefile2.php public_html
Change Directory:
sftp> cd public_html
Local Commands:
Check Local Working Directory:
sftp> lpwd
Output: Local working directory: /home
List Local Directory Contents:
sftp> lls
Output:
config.php index.html local var
Change Local Directory:
sftp> lcd var
Transferring Files with SFTP #
From Remote to Local:
- Download a File:
sftp> get examplefile1.txt
Download and Rename:
sftp> get examplefile1.txt localexample.txt
Download Directory Recursively:
sftp> get -r public_html/
From Local to Remote:
sftp> put examplefile1.txt
Upload Directory Recursively:
sftp> put -r var
Basic File Manipulation
Change Owner:
sftp> chown userID file
Change Group:
sftp> chgrp groupID remotefilename
Change Permissions:
sftp> chmod 755 public_html
Set Local Umask:
sftp> lumask 022
Exiting SFTP
When you have finished with SFTP, you can use exit or bye to close the connection:
sftp> bye
Final Words
While SFTP is a relatively simple tool, it’s very useful for administering servers and moving files between them. If you’re using FTP or SCP for your transfers, SFTP is a good way to have the strengths of both. It provides a secure, effective, and useful tool for file transfer and server management.