SFTP also known as Secure FTP or SSH FTP is a secure way of transferring files from your local machine to your remote web server. What needs to be noted is that in most cases you do not need to have SSH shell access enabled in your account or even configure private and public keys in order to use SFTP. You should be able to connect via SFTP using a regular FTP program like Filezilla or WinSCP simply by accessing a different port. The FTP port is generally Port 21 and SFTP port is generally Port 22 depending on your hosting service.
If you are not able to connect to your server using Port 22, make sure to contact your web host and get the right port for SFTP. Some hosts will want you to enable shell access in your account in order for you to use SFTP. Depending on the host, this will be enabled free of cost or for a one time payment. There is also a possibility that you would need to configure private and public keys in order to use SFTP. In this tutorial though, we are only going to look at using SFTP without having to configure private/public keys. This technique should work for most shared hosting accounts and is suffice.
Using WinSCP to SFTP
There are a host of free FTP programs that you can use to connect to your web server. Some of the best ones are Filezilla and WinSCP. In this tutorial I am going to use WinSCP. If you don't have WinSCP, you can download it free from here: http://winscp.net/eng/download.php
Steps to Download, Install and Use WinSCP are as follows:
Step 1: Download the 'Installation Package' by visiting the WinSCP download page.
Step 2: Once downloaded, check out the installation guide. Make sure to select the 'Commander interface' while installing.
Step 3: Once installed, open the program and click 'New Site' to create a new SFTP connection and enter settings as shown in the image below:
- File Protocol: Select SFTP.
- Host Name: Enter your domain name here with a ftp. preceding it. Eg: ftp.yourdomainname.com or ftp.yourdomainname.net
- Port Number: Set the port number to 22. This is the port that most hosts use for SFTP connections. If this does not work, try setting the port to 2222 or 2200. If nothing works, contact your web host. The port for regular FTP connections is Port 21. So if SFTP does not work, you can use FTP for temporary connections and uploads. Make sure to change the 'File Protocol' to FTP.
- Username and Password: Enter the username and password of your website's cpanel/hosting control panel login.
Once you have entered these settings, click save. Once you click save, there will a dialog box which pops up with an option to save your password. Check this box if you would like to save your password.
If you don't save your password, you will need to re-enter your password each time you want to login to your web-server.
If you are concerned about security of saving your password, make sure to set a master password. This way, WinSCP will prompt you for a master password each time someone initiates a login to your web server. To set a master password go to 'Tools > Preferences > Security > Master Password'.
Step 4: To connect to your server, double click on the sitename listed in the left panel as shown in the image below and click, login.
Step 5: Once you do this, you should be presented with a 'unknown server' warning message which looks as follows:
Click yes to proceed connecting to your server. Note that this security message will only be shown the first time you login to your server. You will not receive this message during subsequent logins.
Step 6: You should have connected to your server now and be presented with the following interface:
The left side of the interface (Indicated by A in the image) displays the files in your local machine and the right side (Indicated by B in the image) displays files in the remote server.
As shown in the image, double click on the public_html folder. All your files should be uploaded here. Please note that this is specific to CPanel. If you don't see a public_html, ask your host which folder you should upload your files to.
Step 7: To begin uploading files, browse to the folder containing your files in the local computer section. In the remote server section, double click on public_html folder.
To upload a single file/folder, right click on the file/folder and then click 'Upload' as shown in the image above. To upload multiple files and folders use CTRL + Click to select multiple files/folders and then click upload.
All files uploaded to the public_html folder can be accessed via a URL in a web-browser like IE, Chrome or Firefox.
For example, if you uploaded a file named 'article.html', you should now be able to access this file by going to 'http://sitename.com/article.html'
Similarly, if you uploaded a folder named 'blog' and then a file named 'article.html' within that folder then you will be able to access this file by going to 'http://sitename.com/blog/article.html'.
Once the upload is completed, for all future uploads, make sure that the location on your local computer matches the location on your remote server.
For example, if you want to upload a file named 'article.html' which resides in the folder 'blog' on your local machine, you need to go to the similar location in your remove server by double clicking 'public_html' and then double clicking the 'blog' folder and then upload/update the 'article.html' in there.