scp copying from a hard drive through a server - ssh

I want to scp copy some files from a hard drive to my local disk. To ssh to the hard drive, I first have to ssh to a server, then ssh from there on to the hard drive. Normally I'd just copy the files to a location on the server, then scp them to my machine e.g:
scp -r user#server.example.com: ~/folder/ ./
The files I want to copy this time are too big to do that. How do I scp directly from the hard drive through the server?

Set up a ssh proxy on the server that tunnels to the hard drive (which has its own ssh server right?)
Check this out:
https://serverfault.com/questions/341190/forward-ssh-through-ssh-tunnel

This should be similar to using scp with a server and your local machine, but use the mounted path to/from the hard drive in place of the path to/from your local machine.
scp -r user#server.example.com: ~/folder/ /Volumes/NameOfDrive

Related

cp: cannot create regular file ‘Users/James/Desktop’: No such file or directory

I'm trying to copy a file from a remote server to my desktop and i'm getting the above error. I've SSH'd to the server.
Here is what i'm doing:
deploy#ip-10-91-135-76 /data/project/current/lib/data $ scp customer_record.ods /Users/James/Desktop
I have very limited experience and don't understand what is going on?
Thanks a lot
man scp tells you how to use scp. In particular, most usages look like:
scp [user1#]host1:]file1 [[user2#]host2:]file2
You can omit putting the user in if its the same as your current user, and likewise for the host. Since you've SSH'd onto the server already, the start of your command is okay to be scp customer_records.ods, but the next argument has to include the user name and host of the target machine that you want to copy the file to, namely your home computer. Chances are you actually want to go the other way, since your home computer may not have a publicly accessible IP.
End the SSH session, go back to your home machine.
Do:
scp <user-you-sshd-as>#<server-you-sshd-to>:/data/project/current/lib/data/customer_records.ods /Users/James/Desktop
If you need to specify a private key, you can use the -i option: scp -i <path-to-key> ...

How to copy a directory from local machine to remote machine

I am using ssh to connect to a remote machine.
Is there a way i can copy an entire directory from a local machine to the remote machine?
I found this link to do it the other way round i.e copying from remote machine to local machine.
Easiest way is scp
scp -r /path/to/local/storage user#remote.host:/path/to/copy
rsync is best for when you want to update versions where it has been previously copied.
If that doesn't work, rerun with -v and see what the error is.
It is very easy with rsync as well:
rsync /path/to/local/storage user#remote.host:/path/to/copy
I recommend the usage of rsync over scp, because it is highly likely that you will one day need a feature that rsync offers and then you benefit from your experience with the tool.
This is worked for me
rsync -avz -e 'ssh' /path/to/local/dir user#remotehost:/path/to/remote/dir
this is if you have to used another ssh port other than 22
rsync -avzh -e 'ssh -p sshPort' /my/local/dir/ remoteUser#host:/path/to/remote/dir
this works if your remote server uses default 22 port
rsync -avzh /my/local/dir/ remoteUser#host:/path/to/remote/dir
This worked for me.
Follow this link for detailed understanding.
we can do this by using scp command for example:
scp -r /path/to/local/machine/directory user#remotehost(server IP Address):/path/to/sever/directory
In case of differnt port
By default, the SCP protocol operates on port 22 but this can be overridden by supplying the -P flag, followed by the port number for example:
scp -P 8563 -r /path/to/local/machine/directory user#remotehost(server IP Address):/path/to/sever/directory
NOTE: we use -r flag to copy directory's files/folders recursively instead of a single file.

If you scp a file over an ssh tunnel does the file get encrypted twice?

Backgound info:
Server A needs to send data to Server B but I am not permitted to open any additional ports in the firewall between them. There is an ssh port open, so I chose to send data through an ssh tunnel. However, I now need to copy files from A to B as well.
Question:
If I scp files from A to B over my existing ssh tunnel do the files get encrypted twice? Or is scp "smart enough" to utilize the existing tunnel?
I want to avoid the additional overhead of encrypting twice if possible.
Are there other ways to send files over an ssh tunnel?
Not sure about the double encryption (I would guess yes), but why use scp over an ssh tunnel? scp is using an ssh connection, therefore, no problem with firewalls etc.
If you're looking for an alternative, you can use rsync over ssh with something like the following:
rsync -avz -e ssh /home/me myname#servername:/some/folder
Hope this helps.

shell script for copying from remote server to local computer using ssh tunneling - scp

I have managed to connect to a remote server through ssh tunneling. No how can I copy files from remote server to my local computer. Considering that I just want to do it from remote server to my local computer.
I dont know how to write this command
"scp file/I/want/to/copy localhost/home/folder"
thanks a lot
Example:
scp username#server:/home/username/file_name /home/local-username/file-name
check this:
http://www.garron.me/linux/scp-linux-mac-command-windows-copy-files-over-ssh.html
scp -r (source)hostname:/(location of the file to be copied)/(file name) (Destination)hostname:/(location of the folder where the file should be copied to)
For example:
scp -r ram.desktop.overflow.com:/home/Desktop/Ram/abcd.txt rajesh.desktop.overflow.com:/home/documents/

Transferring files over SSH [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I'm SSHing into a remote server on the command line, and trying to copy a directory onto my local machine with the scp command. However, the remote server returns this "usage" message:
[Stewart:console/ebooks/discostat] jmm% scp -p ./styles/
usage: scp [-1246BCEpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user#]host1:]file1 [...] [[user#]host2:]file2
[Stewart:console/ebooks/discostat] jmm%
I'd like to be able to transfer files in both directions. From what I read, I thought the above command would work for downloading, and scp -p [localpath] [remotepath] for uploading?
You need to scp something somewhere. You have scp ./styles/, so you're saying secure copy ./styles/, but not where to copy it to.
Generally, if you want to download, it will go:
# download: remote -> local
scp user#remote_host:remote_file local_file
where local_file might actually be a directory to put the file you're copying in. To upload, it's the opposite:
# upload: local -> remote
scp local_file user#remote_host:remote_file
If you want to copy a whole directory, you will need -r. Think of scp as like cp, except you can specify a file with user#remote_host:file as well as just local files.
Edit: As noted in a comment, if the usernames on the local and remote hosts are the same, then the user can be omitted when specifying a remote file.
If copying to/from your desktop machine, use WinSCP, or if on Linux, Nautilus supports SCP via the Connect To Server option.
scp can only copy files to a machine running sshd, hence you need to run the client software on the remote machine from the one you are running scp on.
If copying on the command line, use:
# copy from local machine to remote machine
scp localfile user#host:/path/to/whereyouwant/thefile
or
# copy from remote machine to local machine
scp user#host:/path/to/remotefile localfile
You need to specify both source and destination, and if you want to copy directories you should look at the -r option.
So to recursively copy /home/user/whatever from remote server to your current directory:
scp -pr user#remoteserver:whatever .
No, you still need to scp [from] [to] whichever way you're copying
The difference is, you need to scp -p server:serverpath localpath