pages tagged file-transferyakkinghttp://yakking.branchable.com/tags/file-transfer/yakkingikiwiki2014-01-29T12:00:26ZTransferring files between computershttp://yakking.branchable.com/posts/xfer-files/Lars Wirzenius2014-01-29T12:00:26Z2014-01-29T12:00:08Z
<p>From time to time you will need to transfer files between computers.
You will probably, for example, publish release tar archives, or
transfer log files for debugging to another computer. There are a
variety of ways of doing this, and you may need to choose the one to
use depending on circumstances.</p>
<ul>
<li><code>rsync</code> is good when you have already transferred one version of a
file or directory tree, and need to transfer updates. It is quite
remarkably efficient at that. It requires to be installed on the
other end.</li>
<li><code>sftp</code> and <code>scp</code>, which are provided by <code>ssh</code>, are good for
transfers across untrusted networks (i.e., any network except your
own, and even that may be suspect).</li>
<li><code>nc</code> (netcat) can be a good thing, <strong>on a trusted network</strong>, for
transferring data as quickly as possible, since it is doesn't do any
encryption. Despite this, it doesn't require transferring a password
in cleartext. <code>nc</code> can be combined with <code>tar</code> or <code>cpio</code> to transfer
more than one file at a time.</li>
</ul>
<p>You probably want to avoid, if at all possible, the following:</p>
<ul>
<li><code>ftp</code> is completely unencrypted (including sending your password
in cleartext), and often difficult to get through firewalls.</li>
<li><code>rcp</code>, which is like <code>scp</code>, but is completely insecure. Luckily, it
is rarely even installed, except as an alias for <code>scp</code>.</li>
</ul>
<h1>Example</h1>
<p>Let's assume we are in a directory that we want to transfer to another
computer, <code>other.example.com</code>, as the directory <code>/tmp/foo</code> on the
remote computer. Here are a few ways to do the transfer:</p>
<p>Rsync and scp are equally simple:</p>
<pre><code>rsync -r . other.example.com:/tmp/foo/.
scp -r . other.example.com:/tmp/foo/.
</code></pre>
<p>With Rsync, you may want to consider more options as well, such as
<code>--delete</code>, to make sure any extra files on the target end get
deleted. If you do that, then also test it with <code>--dry-run</code>.</p>
<p>Netcat requires a bit more setup. On the remote end, you'd run it like
this:</p>
<pre><code>nc -l -p 12765 | tar -xf -
</code></pre>
<p>On the local (sending) end, you run it like this:</p>
<pre><code>tar -cf . | nc localhost 12765
</code></pre>
<p>Note that there are at least two versions of <code>nc</code> out there, with
incompatible command line syntaxes. This example uses the syntax from
the version in the Debian <code>netcat-openbsd</code> package.</p>
<p>You can send from the remote end to the local end as well, and you can
choose which end connects and which end listens, depending on the
situation. For example, if your remote end has a firewall that
prevents it from listening, you'd listen on your local end instead.</p>
<p>(But, remember, only do this if your network is trusted. Otherwise
someone can get the file instead.)</p>