0% found this document useful (0 votes)
13 views4 pages

SSH Network File Copy Methods

This document provides examples of using SSH (Secure Shell) to copy files between a local and remote system. It describes using SSH to push (upload) files from local to remote, pull (download) files from remote to local, and compare files between the two systems. Various compression and archiving techniques are also demonstrated that can be used with SSH for efficient file transfers.

Uploaded by

Mairton Júnior
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

SSH Network File Copy Methods

This document provides examples of using SSH (Secure Shell) to copy files between a local and remote system. It describes using SSH to push (upload) files from local to remote, pull (download) files from remote to local, and compare files between the two systems. Various compression and archiving techniques are also demonstrated that can be used with SSH for efficient file transfers.

Uploaded by

Mairton Júnior
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Network File Copy using SSH [Link]

html

Network File Copy using SSH


Updated February 20, 2003
Created April 23, 2001

Please note that &&, ||, and -, are documented at the bottom of this page.

PUSH:

tar cvf - . | gzip -c -1 | ssh user@host cat ">" [Link]

ssh target_address cat <localfile ">" remotefile


ssh target_address cat <localfile - ">" remotefile
cat localfile | ssh target_address cat ">" remotefile
cat localfile | ssh target_address cat - ">" remotefile
dd if=localfile | ssh target_address dd of=remotefile
ssh target_address cat <localfile "|" dd of=remotefile
ssh target_address cat - <localfile "|" dd of=remotefile
( cd SOURCEDIR && tar cf - . ) | ssh target_address "(cd DESTDIR && tar xvpf - )"
( cd SOURCEDIR && tar cvf - . ) | ssh target_address "(cd DESTDIR && cat - >
[Link] )"
( cd SOURCEDIR && tar czvf - . ) | ssh target_address "(cd DESTDIR && cat - >
[Link] )"
( cd SOURCEDIR && tar cvf - . | gzip -1 -) | ssh target_address "(cd DESTDIR && cat -
> [Link] )"
ssh target_address "( nc -l -p 9210 > remotefile & )" && cat source-file | gzip -1 -
| nc target_address 9210
cat localfile | gzip -1 - | ssh target_address cat ">" [Link]

PULL:
ssh target_address cat remotefile > localfile
ssh target_address dd if=remotefile | dd of=localfile
ssh target_address cat "<" remotefile >localfile
ssh target_address cat "<" [Link] | gunzip >localfile

COMPARE:
###This one uses CPU cycles on the remote server to compare the files:
ssh target_address cat remotefile | diff - localfile

1 of 4 30-03-2011 21:44
Network File Copy using SSH [Link]

cat localfile | ssh target_address diff - remotefile


###This one uses CPU cycles on the local server to compare the files:
ssh target_address cat <localfile "|" diff - remotefile

Push: Push local file to remote server.


Pull: Pull remote file from remote server to local machine.

Of course there is always ftp, scp2, nfs, smb and other methods as well.

The above methods make a great Ghost replacement.


One can boot a system using standalone linux on a floppy, such as tomsrtbt and
can then proceed to:

1. backup the local hard drive to a remote server or


2. download an image from the remote server and place it on the local hard
drive.

RSH works just the same as SSH I'm sure, it's jut that ssh or ssh should give
you better security.

Note: Compressing and then transferring data is faster than transferring


uncompressed data. Use compression before sending data over the wire to
achieve faster data transfer speeds.

localfile and remotefile can be files, directories, images, hard drive partitions, or
hard drives.

Moving files around on local filesystem:

( cd SOURCEDIR && tar cf - . ) | (cd DESTDIR && tar xvpf - )

FTP VIEW:

ftp> get [Link] "| xv -"


ftp> get README "| more"

FTP PUSH:

ftp> put "| tar cvf - ." [Link]


ftp> put "| tar cvf - . | gzip " [Link]

2 of 4 30-03-2011 21:44
Network File Copy using SSH [Link]

FTP PULL:

ftp> get [Link] "| tar xvf -"

Pipes and Redirects:

zcat [Link].Z | gv -
gunzip -c [Link] | gv -
tar xvf [Link]
tar xvf - < [Link]
cat [Link] | tar xvf -
tar cvf [Link] .
tar cvf - . > [Link]
tar cf - . | (cd ~/newdir; tar xf -)
gunzip -c [Link] > bar
cat [Link] | gunzip > bar
zcat [Link] > bar
gzip -c foo > [Link]
cat foo | gzip > [Link]
cat foo | gzip > [Link]

SSH Keys

see [Link]

Explanation of &&, ||, and -

&& is shorthand for "if true then do"


|| is shorthand for "if false then do"
These can be used separately or together as needed. The following examples
will attempt
to change directory to "/tmp/mydir"; you will get different results based on
whether
"/tmp/mydir" exists or not.
cd /tmp/mydir && echo was able to change directory
cd /tmp/mydir || echo was not able to change directory
cd /tmp/mydir && echo was able to change directory || echo was not able to
change to directory
cd /tmp/mydir && echo success || echo failure
cd /tmp/mydir && echo success || { echo failure; exit; }

3 of 4 30-03-2011 21:44
Network File Copy using SSH [Link]

The dash "-" is used to reference either standard input or standard output. The
context in which the dash is used is what determines whether it references
standard input or standard output.

Homepage: [Link]
Site Map: [Link]

4 of 4 30-03-2011 21:44

Common questions

Powered by AI

SSH uses command syntax involving pipes and redirects for direct terminal operations, providing encrypted, flexible command-line interactions. FTP's command syntax is more restrictive and does not natively support encryption. SSH integrates with tools like tar and gzip for seamless data compression during transfer, whereas FTP requires additional steps for similar functionality .

Standalone Linux systems offer isolation and often reduced attack surfaces for secure data backups over SSH, beneficial in environments with minimal infrastructure. Networked systems provide greater resource availability and ease of integration but pose higher security risks if improperly configured. The decision depends on the balance between security needs, resource availability, and administrative overhead .

Using SSH keys for automated login increases efficiency by allowing scripts to run without manual password intervention, thus facilitating unattended file transfers. It enhances security by using cryptographic keys rather than passwords, which are less susceptible to brute force attacks. However, managing key pairs requires careful control to prevent unauthorized access .

To push files using SSH, data is sent from the local machine to the remote server using commands like 'tar | ssh'. For pulling, data is fetched from the remote server to the local machine using commands such as 'ssh target_address cat remotefile > localfile'. This method ensures that all transfers are secured by SSH encryption .

Using SSH as a Ghost replacement enhances network file copy tasks by offering encrypted transfer processes, which improve security over unencrypted methods. With SSH, both system images and backups can be managed securely and efficiently from remote locations, leveraging standalone Linux setups .

Compressing data before transferring it over a network can significantly improve transfer speeds. This is because compressed data takes less space and thus requires less bandwidth, allowing for faster data transmission. The document highlights that compressing data before sending it over the wire results in augmented performance, making transfers more efficient .

The use of standalone Linux with SSH for remote backups allows flexibility and increased security due to encryption. It facilitates backing up a system securely or restoring from a remote image efficiently. However, it might be complex for users unfamiliar with command-line operations, and network setup needs to be secure and reliable to ensure successful operations .

Pipes and redirects enable efficient data handling and manipulation during SSH-based file operations by allowing transformations like compression and decompression on-the-fly. This minimizes disk I/O by streaming data directly between commands, such as compressing files with gzip before sending them over SSH, thereby reducing file size and speeding up transmission .

SSH (Secure Shell) is used for network file copy to provide encrypted communication, ensuring that data transferred between local and remote machines is secure. Unlike older methods such as RSH or unencrypted FTP, SSH encrypts data in transit, protecting against eavesdropping, man-in-the-middle attacks, and other security vulnerabilities .

In SSH and command-line environments, '&&' is used to execute a command if the preceding command is successful, '||' is used to execute a command if the preceding command fails, and '-' is used to represent either standard input or output depending on the context. These operators help to control the flow of command execution efficiently .

You might also like