Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

UNIX Terminal – Secure Copy (SCP)

Posted on May 31, 2016May 31, 2016 By David Kittell

Secure Copy (SCP) is a useful UNIX command that allows you to securely copy files and directories between your local machine and a remote computer.

In the examples below “-P 22” is not actually needed if the SSH port is 22. Many of the servers I connect to have a different port for security reasons so I’ve included it.

While I wouldn’t recommend this as a port for SSH it works as a good example, if you have port 1234 for SSH your command would change from “-P 22” to “-P 1234”

Make sure the P is a capital P

If you need more explanation or information about SCP you can do this command in terminal

man scp

First to upload a file you need a command like below, an understanding of each file system is helpful.

In the example below we connect to the remote computer 192.168.1.40 with username “testuser” on port 22 to send “SomeFile.txt” in our home directory to the files directory in the home folder of “testuser” on the remote computer.

NOTE: if you have a hostname/domain you can use that instead of the IP

scp -P 22 ~/SomeFile.txt testuser@192.168.1.40:~/files

Now if you reverse the command you can download.

In the example below we connect to the remote computer 192.168.1.40 with the username “testuser” on port 22 to get “SomeFile.txt” in the files directory in the home folder of “testuser” on the remote computer and download it to our home directory

scp -P 22  testuser@192.168.1.40:~/files/SomeFile.txt ~/

Now as before we can also download/upload entire directories as well.

In this example we must include “-r” to define recursive or all files in directory

scp -r -P 22 testuser@192.168.1.40:~/files/ ~/
scp -r -P 22 ~/ testuser@192.168.1.40:~/files/

If you have a server that you connect to that doesn’t use a password but uses a shared key you simply need to add that to the command.

scp -r -P 22 -i ~/Documents/SomeKey.key testuser@192.168.1.40:~/files/ ~/
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

CentOS Code Fedora Mac OS X Shell Mac OSX Red Hat Ubuntu UNIX UNIX Shell Scripts

Post navigation

Previous post
Next post

Related Posts

Distinct Query On One Column

Posted on May 20, 2014October 26, 2015

While this query has more than what may be needed this will help you to get data based on one unique column. SELECT [File Name] ,[Division] ,[Version] FROM ( SELECT [File Name] ,[Division] ,[Version] ,row_number() OVER ( PARTITION BY [Division] ORDER BY [Version] DESC ) AS RowNumber FROM <DatabaseTableName> )…

Read More

Ektron Content Type

Posted on October 21, 2013October 26, 2015

Public Function GetContentType(ByVal sId As String) As String Select Case [sId] Case "1" Return "Content" Case "2" Return "Forms" Case "3" Return "Archive Content" Case "4" Return "Archive Forms" Case "7" Return "Library Item" Case "8" Return "Assets" Case "9" Return "Archive Assets" Case "12" Return "Archive Media" Case "99"…

Read More

Drop Function If Exists

Posted on August 6, 2013October 26, 2015

IF OBJECT_ID(N’dbo.RegexReplace’) IS NOT NULL DROP FUNCTION dbo.RegexReplace GO Source: https://www.simple-talk.com/sql/t-sql-programming/tsql-regular-expression-workbench/ Originally Posted on August 6, 2013Last Updated on October 26, 2015 All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes