sftp Command in Linux

Learn via video courses
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Overview

The Secure File Transfer Protocol, or SFTP, is a protocol used for securely transferring files over network connections. The 'sftp' command in Linux is the client-side command for this protocol. It provides a secure, encrypted channel to transfer files between local and remote systems, while ensuring data integrity and confidentiality. This article aims to delve into the details of the 'sftp' command in Linux, exploring its syntax, options, and various use cases.

Syntax of sftp Command in Linux

The basic syntax of the sftp command in Linux is as follows:

Where:

  • options: These are flags or parameters that modify the behavior of the sftp command.
  • user@host: This specifies the remote host to which you are connecting. You may also optionally include the username to use for the connection.
  • dir: This is an optional parameter to specify a directory on the remote host.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Options in sftp Command in Linux

  1. -P: Specify the port number of the remote host.

    For example -

    Output:

    This command initiates a secure file transfer session to 'remotehost' on port 2222.

  2. -b: Use a batch file for automating tasks without user interaction.

    For example -

    Output:

    This command executes the commands in 'batchfile.txt' on 'remotehost'.

  3. -C: Enables compression of the data before it's sent.

    For example -

    Output:

    This command initiates a secure file transfer session with 'remotehost' with compression enabled.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example Usages

  • Upload a file to the remote host:

    Output:

    Explanation: This command uploads 'localfile.txt' from your local system to the connected remote host.

  • Download a file from the remote host:

    Output:

    Explanation: This command downloads 'remotefile.txt' from the connected remote host to your local system.

Tips

  • You can use the 'ls' command within an sftp session to list the files in the current directory on the remote host.

  • Remember to use the 'exit' command to end your sftp session once you have finished your tasks.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Advanced Use Cases of sftp Command in Linux

  • Use of wildcard (*) in SFTP:

    Output:

    Explanation: This command downloads all files starting with 'file' from the connected remote host to your local system.

  • Renaming a file on the remote server:

    Output:

    Explanation: This command renames 'oldfile.txt' to 'newfile.txt' on the connected remote host.

  • Creating a directory on the remote server:

    Output:

    Explanation: This command creates a new directory named 'newdir' on the connected remote host.

Conclusion

  • SFTP is a secure method for transferring files over a network connection.

  • SFTP sessions can be customized using a variety of options.

  • The SFTP command in Linux allows for a range of file and directory operations, from uploading and downloading to renaming and creating new directories.