Introduction
File Transfer Protocol (FTP) was once a widely used but insecure method for transferring files between remote systems. However, due to its lack of security, it has been deprecated by most modern software as of 2022. Secure File Transfer Protocol (SFTP), on the other hand, addresses the security concerns by integrating with SSH and providing a secure means of file transfer. SFTP is recommended over FTP for its enhanced security features and the ability to leverage SSH connections.

Connecting with SFTP
SFTP utilizes the SSH protocol for authentication and secure connections. It supports various authentication methods, including passwords, but it is advisable to use SSH keys for increased security. Ensure you have SSH keys set up by referring to the SSH key setup guide.

To test SSH access, use the following command:

ssh sammy@your_server_ip_or_remote_hostname

If successful, exit the SSH session using:

exit

Establish an SFTP session with:

sftp sammy@your_server_ip_or_remote_hostname

For custom SSH ports, use:

sftp -oPort=custom_port sammy@your_server_ip_or_remote_hostname

Getting Help in SFTP
The “help” command is crucial for understanding SFTP commands. Enter either of these commands:

help

or

?

This displays a list of available commands.

Navigating with SFTP
SFTP commands for navigation are similar to shell commands. Check the remote system’s current directory with:

pwd

View remote directory contents:

ls

For detailed information, use:

ls -la

Change directory with:

cd testDirectory

To interact with the local file system, prefix commands with “l”. For example:

lpwd
lls
lcd Desktop

Transferring Files with SFTP
Download files from the remote host using:

get remoteFile

To specify a different local file name:

get remoteFile localFile

For directories and contents:

get -r someDirectory
get -Pr someDirectory

Upload local files to the remote system:

put localFile
put -r localDirectory

Useful commands include:

df -h

To run local commands, enter the “!” command. Return to SFTP with:

exit

Simple File Manipulations with SFTP
Perform filesystem housekeeping with SFTP:

chown userID file
chgrp groupID file
chmod 777 publicFile

Read /etc/passwd and /etc/group for UID and GID information:

get /etc/passwd
!less passwd

get /etc/group
!less group

Set local umask for downloaded files:

lumask 022

Create directories on both local and remote systems:

lmkdir localDirectory
mkdir remoteDirectory

Other file-related commands for the remote system:

ln
rm
rmdir

For local system actions, use the “!” command:

!

Close the SFTP connection with:

bye

Conclusion
SFTP, with its integration into SSH, provides a secure and efficient way to transfer files. Understanding its commands and features enhances your ability to manage files seamlessly and securely.

Similar Posts