Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
198
rated 0 times [  198] [ 0]  / answers: 1 / hits: 357015  / 1 Year ago, sat, april 29, 2023, 9:05:55

I ssh-ed into my webhost's directory, and tar-ed the webapp to download. When I try to mv to ~/mydirectory/backups or /home/mydirectory/backups, it defines the "home" as my root on the webhost that I'm ssh'ed into.



How do I mv in ssh to a local drive while still being inside the webhost's system?


More From » ssh

 Answers
6

First things first: ssh is a way to remotely login to another computer. The shell (command line) you get after you ssh is (pretty much) the same as if you had opened a xterm in the remote machine. If offers no such way to move files.


However, the fact that the remote computer accepts ssh connections gives you some options to exchange files:


Use scp
To copy from your local computer to the remote, type, in the local computer:


scp /tmp/file [email protected]:/home/name/dir


(where /tmp/file can be replaced with any local file and /home/name/dir with any remote directory)


To copy from the remote computer to the local one, type, in the local computer:


scp [email protected]:/home/name/dir/file /tmp


Use sshfs
This is a little more advanced but much, much nicer (when the internet connection of both computers is good. If not, stick to scp)


You can "link" a directory from the remote computer to an (empty) directory of the local computer. Say you "link" the /some/remote/dir from the remote computer to /home/youruser/remotecomp in your computer. If there is a file /some/remote/dir/file in the remote computer, you can see it on /home/youruser/remotecomp/file. You can copy and mv as usual, and you can even alter remote files and dirs.


Note however, that when the connection ends, /home/youruser/remotecomp becomes an empty dir again, and you only keep in the local computer the files you copied to other directories


To achieve this:



  1. install sshfs:


sudo apt-get install sshfs



  1. create a empty dir


mkdir /home/youruser/remotecomp



  1. "link" the two directories (the right term is mount)


sshfs [email protected]:/some/remote/dir /home/youruser/remotecomp



  1. Enjoy



  2. "unlink" the dirs




fusermount -u /home/youruser/remotecomp


If the local computer runs windows
You can find versions of scp for windows. See, e.g, winscp


Rsync
rsync is a utility to copy files that can:



  • resume transfers

  • redo a transfer, but only send the files that changed.


To copy a single file, you can use rsync -P -e ssh /tmp/file [email protected]:/home/name/dir


To keep a directory in sync, sending only the needed files, you can use rsync -avzh /home/yourname/dir_name [email protected]:/var/temp/


There are also many other options, including deleting files in the remote dir if they no longer exist in the local dir.


This option is a bit harder. For example, you can mess up with trailing slashes (note that, in the last command, dir_name had no trailing slash, but /var/temp/ had). So it is useful, but requires a bit of testing and/or man rsync


As always, commands are run in the local computer, not the remote one


[#37208] Sunday, April 30, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
smelrop

Total Points: 263
Total Questions: 122
Total Answers: 108

Location: Saudi Arabia
Member since Thu, Jan 28, 2021
3 Years ago
smelrop questions
Mon, Mar 13, 23, 07:22, 1 Year ago
Sun, Feb 5, 23, 13:02, 1 Year ago
Tue, Aug 31, 21, 00:50, 3 Years ago
Sat, Dec 18, 21, 15:18, 2 Years ago
;