Solved

Copy file (cp) from one command line (BSD) to another.

Posted on 2010-09-12
6
429 Views
Last Modified: 2012-06-27
logged in via ssh, need to copy a file from another machine back to my machine.
What is the command for the extraction of the file.
I know how to cp a file from directory to directory or mv, can't remember the command.
Unix.
0
Comment
Question by:T_Myles
6 Comments
 
LVL 6

Expert Comment

by:sagiamar
Comment Utility
0
 
LVL 68

Expert Comment

by:woolmilkporc
Comment Utility
scp /source/file user@targethost:/target/directory/
or
scp user@sourcehost:/source/file /target/directory/
0
 

Author Comment

by:T_Myles
Comment Utility
woolmilkporc:

I'm in the machine via ssh I want to send file to another remote server.
A directory is what I want to cp over.

Since I'm inside the machine, shouldn't there be a -R included, I'm confused about the second line.
If I can rap my head around the path I can get it.  
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 2

Expert Comment

by:anoym
Comment Utility
To copy files and subdirectories I'm using:

# scp -r -p /source_directory/* username@ip_adresse:/target_directory

To copy a whole directory you can use:

# scp -r -p /source_directory username@ip_adresse:/target_directory

and pls check:

http://amath.colorado.edu/computing/software/man/scp.html

0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
Comment Utility
My first line is for copying a file /source/file from the machine you're logged in to a remote server named targethost as user user into the directory /target/directory there.
My second line is for copying a file /source/file from a remote server named sourcehost as user user into the local directory /target/directory
By the way, with scp you can even copy a file/files from one remote machine to another remote machine while being logged in via ssh to a third, arbitrary machine, and moreover, you can give it a new name (the italic string in angle brackets (  <... > ) is meant to indicate the shell prompt!)
<user0@somehost0> ssh user1@somehost1  # (or via PuTTY, or whatever)
<user1@somehost1> (Logged in)
<user1@somehost1> scp user2@somehost2:/source/file user3@somehost3:/target/directory/new_filename
<user1@somehost1> exit
<user0@somehost0>
 
All of the above is for files, since in your question you asked for copying a file.
There is no "-R" (uppercase R) for scp. To have scp work recursively use the "-r" (lowercase r) flag, as indicated by anonym.
wmp
0
 

Author Closing Comment

by:T_Myles
Comment Utility
Thanks for the detail explanation.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

We all know how boring and exhausting it is to transfer huge web projects developed locally to a webserver simply via FTP. The File Transfer Protocol is a really nice solution if you need to transfer small amounts of files, but if you're plannin…
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now