Hot answers tagged

54

You can pipe tar across an ssh session: $ tar czf - <files> | ssh user@host "cd /wherever; tar xvzf -"


49

Try this line: readlink -f `which command` If command is in your $PATH variable , otherwise you need to specify the path you know.


45

Use rsync, and pass -u if you want to only update files that are newer in the original directory, or --ignore-existing to skip all files that already exist in the destination. rsync -au /local/directory/ host:/remote/directory/ rsync -a --ignore-existing /local/directory/ host:/remote/directory/ (Note the / on the source side: without it rsync would ...


41

You need to pass a literal escape to scp to avoid the remote machine treating * as a glob (notice that it is doubly quoted): scp 'SERVERNAME:/DIR/\*' .


39

There are many ways to do what you want. The simplest is to use a pìpe: tar zcvf - MyBackups | ssh user@server "cat > /path/to/backup/foo.tgz" Here, the compression is being handled by tar which calls gzip (z flag). You can also use compress (Z) and bzip (j). For 7z, do this: tar cf - MyBackups | 7za a -si -mx=9 -ms=on MyBackups.tar.7z | ssh ...


31

scp will overwrite the files if you have write permissions to them. In other words: You can make scp effectively skip said files by temporarily removing the write permissions on them (if you are the files' owner, that is).


31

Newer versions of scp have the option -3 -3 Copies between two remote hosts are transferred through the local host. Without this option the data is copied directly between the two remote hosts


31

Rsync is very well suited for transferring large files over ssh because it is able to continue transfers that were interrupted due to some reason. Since it uses hash functions to detect equal file blocks the continue feature is quite robust. It is kind of surprising that your sftp/scp versions does not seem to support large files - even with 32 Bit ...


30

Ok LOL, I just figured out what the problem is. Since I like cows so much, I've put fortune | cowsay at the top of my .bashrc file which produces output like the following when starting bash: _______________________________________ < You will lose an important disk file. > --------------------------------------- \ ^__^ \ ...


29

A regular file is a file that isn't a directory or more exotic kinds of “special” files such as named pipes, devices, sockets, doors, etc. Symbolic links are not regular files either, but they behave like their target when it an application is accessing the content of the file. You passed root@IP: as the source of the copy and /path/to/picture.jpg as the ...


29

As you say, use rsync: rsync -azP /var/www/html/txt/ username@ip-address:/var/www/html/txt The options are: -a : enables archive mode, which preserves symbolic links and works recursively -z : compress the data transfer to minimise network usage -P : to display a progress bar and enables you to resume partial transfers As @aim says in his answer, make ...


28

You can set that user's shell to rssh or scponly, which are designed precisely for that purpose: rssh is a restricted shell for use with OpenSSH, allowing only scp and/or sftp. It now also includes support for rdist, rsync, and cvs. scponly is an alternative 'shell' (of sorts) for system administrators who would like to provide access to remote ...


27

SSH Supports chrooting an SFTP user natively. You just need to supply ChrootDirectory In your sshd config file, and restart sshd. If you are just doing sftp, then you don't have to do anything more. Unfortunately, this doesn't work for scp. For interactive shell, you will need to copy binaries, and /dev nodes into the chroot. An example config, for ...


27

When copying a directory u need to use a -r option: scp -r root@IP:/path/to/file /path/to/filedestination


27

Use rsync with the --partial option rsync -av --partial sourcedir user@desthost:/destinationdir The --partial will keep partially transferred files. When you resume the rsync transfer after a ssh broken connection, partially transferred files will start resuming from the point where the ssh connection was lost, and also successfully transferred files will ...


26

scp provides a cp like method to copy files from one machine to a remote machine over a secure SSH connection. rsync allows you to syncronise remote folders. They are different programs and both have their uses. scp is always secure, whereas rsync must travel over SSH to be secure.


22

You didn't specify any file: you have to add the file (with path) after the colon: A$ scp <myuserid>@hostB:/absolutepath/file . or A$ scp <myuserid>@hostB:relativepath/file . for a path relative to your home directory. If you don't specify a different user (i.e., the user on A and B are the same) you don't need the @ A$ scp ...


21

SFTP isn't the FTP protocol over ssh, but an extension to the SSH protocol included in SSH2 (and some SSH1 implementations). SFTP is a file transfer protocol similar to FTP but uses the SSH protocol as the network protocol (and benefits from leaving SSH to handle the authentication and encryption). SCP is only for transferring files, and can't do other ...


21

If you did not have the foresight to launch the process with nohup, you can also background the process and disown the bash session while it is running. Open ssh terminal to remote server Begin scp transfer as usual Background the scp process (Ctrl+Z, then bg) Disown the backgrounded process (disown) Terminate the session (exit) and the process will ...


21

You could use rsync (over ssh), which uses a single connection to transfer all the source files. rsync -avP cap_* user@host:dir If you don't have rsync (and why not!?) you can use tar with ssh like this, which avoids creating a temporary file: tar czf - cap_* | ssh user@host tar xvzfC - dir The rsync is to be preferred, all other things being equal, ...


19

You can use the advanced globbing patterns in some shells to match all the files in a directory except for those matching a particular pattern. For example, in ksh, bash or zsh, the command shopt -s extglob ## needed in bash only setopt ksh_glob ## needed in zsh only mv /source/!(*.bak) /destination will move all files in /source to /destination ...


19

I'm not sure about the file size limits of SCP and SFTP, but you might try working around the problem with split: split -b 1G matlab.iso This will create 1 GiB files which, by default, are named as xaa, xab, xac, .... You could then use scp to transfer the files: scp xa* xxx@xxx: Then on the remote system recreate the originial file with cat: cat xa* ...


18

I found Patrick's advice to be correct, although Chris's answer got me on the right track. Use quotes and then you don't need the backslash before the asterisk. scp 'SERVERNAME:/tmp/file_num\*' . scp: /tmp/file_num*.csv: No such file or directory scp 'SERVERNAME:/tmp/file_num*' . judgments_for_job_171642.csv 100% 32KB 32.0KB/s 00:00 ...


18

The syntax for scp is: If you are on the computer from which you want to send file to a remote computer: scp /file/to/send username@remote:/where/to/put Here the remote can be a FQDN or an IP address. On the other hand if you are on the computer wanting to receive file from a remote computer: scp username@remote:/file/to/send /where/to/put scp can ...


17

This is trivial to do with a little script. For example: for server in app0 app1 app4 app5 appN; do scp user@$server:/path/to/log/file /local/path/to/"$server"_file done The above will copy the file from each of the servers sequentially and name it SERVERNAME_file. So, the file from app0 will be app0_file etc. You can obviously change the names to ...


16

You need to run the scp command from the local machine, not on the remote. You don't need the ssh at all: dragonmnl@local $ scp -P 2222 file.ext username@domain:~/ You also don't need the -r: -r Recursively copy entire directories. If you are already logged into the remote machine and want to copy from your local, you need to make sure that ...


15

You can connect to the host using sftp -r and then get the directory. If you forget to use -r when you connect, you can use get -r. sftp -r me@somehost Or sftp> get -r tmp/ Fetching /home/me/tmp/ to tmp Retrieving /home/me/tmp /home/me/new.orig.dmp 100% 417KB 416.8KB/s 00:00 /home/me/untangle.dmp 100% 398KB 398.3KB/s 00:00 ...


15

Something I use fairly often when there is no connection possible between the two servers scp -3 user@server1:/path/to/file user@server2:/path/to/file source -3 Copies between two remote hosts are transferred through the local host. Without this option the data is copied directly between the two remote hosts. Note that this ...


14

Found it!! It seems that in Ubuntu the entries in ~/.ssh/known_hosts are hashed, so SSH completion cannot read them. This is a feature, not a bug. Even by adding HashKnownHosts no to ~/.ssh/config and /etc/ssh/ssh_config I was unable to prevent the host hashing. However, the hosts that I am interested in are also found in ~/.ssh/config. Here is a script ...



Only top voted, non community-wiki answers of a minimum length are eligible