In this article, we will explain how to transfer your files using SFTP.
SFTP is known as SSH File Transfer Protocol or Secure Socket Shell File Transfer Protocol. It is a secure method for transferring files between a client and a server. It uses SSH (Secure Shell) to provide a secure means of accessing a remote server and transferring files securely.
- Before proceeding, it’s important to set up SSH. To confirm whether SSH is configured on your server, follow these steps-
$ ssh eukhost@your_server_ip_or_remote_hostname.
Note: You need to replace “eukhost” with your username and “your_server_ip_or_remote_hostname” with your server IP or hostname
- If it does not log in, then you need to set up SSH access first then you need to exit from the prompt.
$ exit
- Creating an SFTP Session: You can connect to the SFTP session by using the following command.
$ sftp eukhost@your_server_ip_or_remote_hostname
- If you are using a custom SSH port (not the default port 22), then you can also use the following command to connect to SFTP.
$ sftp -oPort=customport eukhost@your_server_ip_or_remote_hostname.
Here, you need to change “customport” to the port number that you are using and this command will connect you to the SFTP with the port you have specified.
- If it does not log in, then you need to set up SSH access first then you need to exit from the prompt.
- Transferring Files with SFTP
- How to Transfer Remote Files to Local System
To transfer files from a remote host, you can do so using the following command.sftp> get remote-file
Here, the remote file will be the name of the files that you need to transfer. When using the “get” command, it will download the “remote file” to your local system, preserving the same name as it had on the server.
- To download the “remote file” from a different remote host to your machine, you can give a different name after the remote file’s name.
sftp> get remote-file local-file
Output Fetching home/eukhost/remote-file to remote-file /home/geeksforgeeks/remote-file 100% 100KB 50.0KB/s 12:05
- Talking about the “get” command it also supports various flags as options. For example, if you want to copy any directory along with all its contents, you need to use the “-r” recursive flag.
- How to Transfer Remote Files to Local System
- How to Transfer Local Files to the Remote System
You can easily transfer files from the local system to the remote system by using the “put” command.sftp> put localFile
Output Uploading local-file to /home/eukhost/local-file local-file 100% 8080 10.4KB/s 12:00
- If you see, the “put” command supports the same optional flags as “get.” This means that to copy a directory with all its files, you can use the following command:
sftp> put -r local-directory
SFTP is a simple way where you can use the FTP or SCP to transfer between local and remote files and folders.
- If you see, the “put” command supports the same optional flags as “get.” This means that to copy a directory with all its files, you can use the following command: