Using SFTP for Remote File Transfer from the Command Line (2024)

Using SFTP for Remote File Transfer from the Command Lineadmin2021-12-05T19:29:50-08:00

The SSH File Transfer Protocol allows you to transfer files from the command line via SSH between a local computer and a specified remote computer. Like SSH, SFTP can be run natively from the shell. This is true of macOS and Linux machines, and is also true of any up-to-date Windows 10 PC (SSH support was added in the Win10 April 2018 update) via PowerShell.

Instantiating an SFTP Connection with a Remote Host

When you are at the command line, the command used to start an SFTP connection with a remote host is:

sftp username@hostname

For example, a user with the username user connecting to the remote host ada would use the following command:

sftp user@ada.cs.pdx.edu

SFTP will then ask for the password to the account you’re trying to log into. After inputting it, the SFTP connection will be instantiated. An SFTP prompt will appear, looking like the following:

sftp>

From here, you can use a few basic linux-like commands to navigate both your directory of your local computer and the remote directory you’re connected to. To end your SFTP session, use theexitcommand. For a full list of SFTP commands, including those outside the scope of this guide, use thehelp command.

Remote Directory Navigation

The pwd command will print your current remote directory path.

The ls command will print the contents of current directory. It can be used with the -l flag to display directory content as a list, or with the -a flag to display hidden files and directories.These flags may be used in conjunction to display all files in a list.

The cd command can be used to change to a different directory. For example, cd Documents would move your working directory to Documents, assuming it existed as a sub-directory within the directory from which you ran the command.

Use cd .. in order to move to the parent directory, e.g. from /home/Documents/ to /home/.

Local Directory Navigation

The aforementioned commands are within the context of the remote directory. In order to navigate your local directory, preface any of the above commands (ls, cd, pwd) with the letter l, like so:

lls, lpwd, lcd

This indicates the command is to take place in the local directory.

Transferring Files

In order to copy a file from the remote directory to the local directory, use the command get. Get expects at least one argument, which specifies the name of the file. This can either be just the filename if it’s in your current working directory, or an absolute file path. If a destination path isn’t specified as a second argument, the get command will default to your local working directory.

To send files to the remote directory, use the put command. This works basically the same as the get command. You must specify the file to be sent to the remote directory, either by name (only if within the current working directory) or absolute file path. If a destination path isn’t specified as a second argument, the put command will default to the remote working directory.

Copying a directory via SFTP is slightly more complicated. This is because most command line implementations of SFTP cannot directly copy a directory, instead you can only copy the contents of a directory. In practice, this means the outermost layer (i.e., the directory itself) will not be copied. You will usually have to make it yourself.

To copy a directory, follow these steps:

  1. Create a local directory of your choice using the commandlmkdir directoryname.
  2. Uselcd directorynameto navigate your working directory into the empty directory you’ve just created.
  3. Move inside the remote directory you want to copy.
  4. From within the remote directory, copy all the files using the commandget -r *.

This will copy all files and sub-directories contained within the directory. This process works same way for transferring a directory to the remote host, but uses theput command.

Another option is to simply compress the directory you’re trying to move, at which point the compressed folder can be transferred like any other file.

Using SFTP to Transfer Files to/from Stashes

From within your SFTP session, typecd /stash/yourstashname. Please be aware that your stash will not show up in the stash directory if you look for it usingls –it can only be accessed directly.

Connecting to your Windows N: drive

To access your N: drive via SFTP, connect to

yourusername@winsftp.cecs.pdx.edu

Note: SFTP uses the SSH protocol, which means that it works natively with any SSH keys you may have configured.

Using SFTP for Remote File Transfer from the Command Line (2024)
Top Articles
How to protect and secure your password manager
2024's Best Banks for ATMs | SmartAsset.com
Pokemon Sapphire Evolution Chart
Top 5 Linux Distributions to Try the KDE Plasma 6 Desktop Right Now - 9to5Linux
Carmel.clay Schools Calendar
Live2.Dentrixascend.com
Att U Verse Outage Map
20 Years at the Getty Center: A Getty Museum Perspective
Spring 2023 Etam Results
Uk Adventure Couple Leak
Used Isuzu Trucks For Sale Craigslist
Valentina Arreaza
'A lot more arrests to come:' Polk sheriff says anti-gang operation arrested 19 people
South Bend Weather Underground
Macaulay Culkin & Brenda Song: From Private Romance to Family of Four
At 25 Years, Understanding The Longevity Of Craigslist
Dinar Guru Recaps Updates
Myapps Tesla Ultipro Sign In
Skip The Games Anchorage
Terrorist Usually Avoid Tourist Locations
Katmoie
Southwest Tracker Live
11 Vintage Houses That Came from a Catalog
Jamie Soricelli Friend Kelly Courtney
Walgreens Colesville
Saberhealth Time Track
How To Power A Fabricator In Ark
Verizon Outage Cuyahoga Falls Ohio
Lycoming County Docket Sheets
Kind Farms Reserve Medical And Recreational Cannabis Photos
Tf2 Cosmetics Tester
Art And Roses 2023
Sunrise Dispensary Clinton Photos
Blower Motor Resistor Autozone
Batting Cages Towson
My Mother Your Mother Lives Across The Street, Prayer For A Chess Player Crossword
Great Clips Hair Salon Near Me
Amazon Ups Drop Off Locations Near Me
My Juno Personal Start Page
Www.21Strepos
Culver's Flavor Of The Day Glendale Wi
Quest Diagnostics Lake Mary - Employer Drug Testing Not Offered
Myusu Canvas
Star Wars Episode 4 Rotten Tomatoes
Ticket To Paradise Showtimes Near Laemmle Newhall
NOXIOUS - Englisch-Deutsch Übersetzung | PONS
Theobromine: Benefits and Side Effects of Cocoa’s Interesting Phytochemical
Jeff Monreal Funeral Home Obituaries
8.7 Increase Of 841
Wanted Old Motorcycles 📞 www.wantedoldmotorcycles.com - wanted - by dealer - sale - craigslist
Arch Aplin Iii Felony
Folamil Genio: Uses, Dosage, Side Effects, FAQ - MedicinesFAQ
Latest Posts
Article information

Author: Dean Jakubowski Ret

Last Updated:

Views: 6516

Rating: 5 / 5 (70 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Dean Jakubowski Ret

Birthday: 1996-05-10

Address: Apt. 425 4346 Santiago Islands, Shariside, AK 38830-1874

Phone: +96313309894162

Job: Legacy Sales Designer

Hobby: Baseball, Wood carving, Candle making, Jigsaw puzzles, Lacemaking, Parkour, Drawing

Introduction: My name is Dean Jakubowski Ret, I am a enthusiastic, friendly, homely, handsome, zealous, brainy, elegant person who loves writing and wants to share my knowledge and understanding with you.