Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Network Services»SSH»How to Download and Upload Files with SFTP Securely

    How to Download and Upload Files with SFTP Securely

    By RahulMarch 11, 20173 Mins Read

    SFTP (SSH File Transfer Protocol) is secured protocol to transfer files between local and remote server. To required SSH server running on the remote system. This protocol encrypts the transfer of data between local and remote system. As SFTP provides secure data transfer, so we recommend it over FTP protocol.

    Advertisement

    SFTP is recommended but in case you only have the FTP server running on remote, use below link for FTP access.

    • How to Download and Upload Files using FTP Command Line

    Connect to SFTP Server:

    SFTP connects to ssh server. You must have the ssh server running on the remote system. Use the following command to connect example.com server as user rahul.

    $ sftp [email protected]
    

    to connect with different port

    $ sftp -P 2222 [email protected]
    
    • How to Use SSH to Connect Remote Linux Server

    After successful authentication, you will get a sftp prompt. Where you can download or upload files securely. To get available commands type help on sftp prompt.

    sftp> help 
    
    Available commands:
    bye                         Quit sftp
    cd path                     Change remote directory to 'path'
    chgrp grp path              Change group of file 'path' to 'grp'
    chmod mode path             Change permissions of file 'path' to 'mode'
    chown own path              Change owner of file 'path' to 'own'
    df [-hi] [path]             Display statistics for current directory or
    ...
    ...
    

    Change Local and Remote Directory

    First check your local and remote server directory using following commands.

    sftp> !pwd
    /home/ubuntu
    
    sftp> pwd
    /home/rahul
    
    • !pwd – Used to check current directory on local system
    • pwd – Used to check current directory on remote system

    Now navigate between directories on local and remote sftp system.

    sftp> lcd /home/ubuntu/Downloads
    
    sftp> cd Uploads
    
    • lcd – Used to navigate between directories on local system
    • cd – Used to navigate between directories on remote system

    Download Files from SFTP

    Use get command to download file from sftp server to local system drive. Use lcd to change location of local download folder. Below command will download remotefile.txt from remote system to local system.

    sftp> get remotefile.txt
    

    To download files and folders recursively use -r switch with get command. Below command will download folder remotedir from remote system to local system recursively.

    sftp> get -r remotedir
    

    Upload Files to SFTP

    Use put command to upload a file from local system to remote system. Use cd to change location of remote upload folder first. the below command will upload localfile.txt from local system to remote sftp system.

    sftp> put localfile.txt
    

    To upload files and folders recursively use -r switch with put command. Below command will upload directory localdir and all files and sub directories to remote server.

    sftp> put -r localdir
    
    • How to Setup SSH Keys on Linux

    file FTP SFTP
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    tail Command in Linux with Examples

    How to Set a Custom SSH Login Banner and MOTD

    How to Install and Secure OpenSSH Server on Pop!_OS

    View 1 Comment

    1 Comment

    1. Brandon .D on August 8, 2017 2:18 pm

      Thanks for the explainer, forgot about ‘cd’ to change locations and pretty much lost myself for a while there!

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to List Manually Installed Packages in Ubuntu & Debian
    • 10 Bash Tricks Every Developer Should Know
    • How to Validate Email Address in JavaScript
    • Firewalld: Common Firewall Rules and Commands
    • 12 Apk Commands in Alpine Linux Package Management
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.