<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us"><generator uri="https://gohugo.io/" version="0.101.0">Hugo</generator><title type="html">ftp on A Scripter's Notes</title><subtitle type="html">Emacs, scripting and anything text oriented.</subtitle><link href="https://scripter.co/categories/ftp/" rel="alternate" type="text/html" title="HTML"/><link href="https://scripter.co/categories/ftp/index.xml" rel="alternate" type="application/rss+xml" title="RSS"/><link href="https://scripter.co/categories/ftp/atom.xml" rel="self" type="application/atom+xml" title="Atom"/><link href="https://scripter.co/categories/ftp/jf2feed.json" rel="alternate" type="application/jf2feed+json" title="jf2feed"/><updated>2026-04-22T08:24:57-04:00</updated><author><name>Kaushal Modi</name><email>kaushal.modi@gmail.com</email></author><id>https://scripter.co/categories/ftp/</id><entry><title type="html">Stuff about command-line ftp</title><link href="https://scripter.co/stuff-about-command-line-ftp/?utm_source=atom_feed" rel="alternate" type="text/html"/><id>https://scripter.co/stuff-about-command-line-ftp/</id><published>2017-01-12T12:07:43-05:00</published><updated>2017-01-12T12:07:43-05:00</updated><content type="html"><![CDATA[<p>To connect to a machine with ip <em>MACHINE</em>, you simply need to enter the below at command-line:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ftp MACHINE
</span></span></code></pre></div><p>See below for a list of commands you would typically use once you <code>ftp</code> to a machine.</p>
<h2 id="basic-ftp-commands">Basic FTP Commands&nbsp;<a class="headline-hash no-text-decoration" href="#basic-ftp-commands">#</a></h2>


<!--- BEGIN RECEIVE ORGTBL ftp-commands -->
<table>
<thead>
<tr>
<th>Command</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>?</code> or <code>help</code></td>
<td>Get help on FTP commands</td>
</tr>
<tr>
<td><code>bye</code> or <code>quit</code></td>
<td>Exit the FTP session</td>
</tr>
<tr>
<td><code>binary</code></td>
<td>Set the mode of file transfer to <em>binary</em></td>
</tr>
<tr>
<td></td>
<td><em>(Provides less chance of transmission error)</em></td>
</tr>
<tr>
<td><code>cd</code>, <code>ls</code>, <code>mkdir</code>, <code>pwd</code>, <code>rmdir</code></td>
<td>Unix operations on remote machine</td>
</tr>
<tr>
<td><code>delete</code></td>
<td>Unix <code>rm</code> operation on remote machine</td>
</tr>
<tr>
<td><code>lcd</code></td>
<td>Unix <code>cd</code> operation on local machine</td>
</tr>
<tr>
<td><code>put</code> <em>FILE</em></td>
<td>Copy 1 file from local to remote</td>
</tr>
<tr>
<td><code>mput</code> <em>FILES</em> (ex: <code>mput *</code>)</td>
<td>Copy multiple files from local to remote</td>
</tr>
<tr>
<td><code>get</code> <em>FILE</em></td>
<td>Copy 1 file from remote to local</td>
</tr>
<tr>
<td><code>mget</code> <em>FILES</em> (ex: <code>mget*</code>)</td>
<td>Copy multiple files from remote to local</td>
</tr>
</tbody>
</table>
<!--- END RECEIVE ORGTBL ftp-commands -->
<!---
#+ORGTBL: SEND ftp-commands orgtbl-to-gfm
| Command                             | Description                                    |
|-------------------------------------+------------------------------------------------|
| `?` or `help`                       | Get help on FTP commands                       |
| `bye` or `quit`                     | Exit the FTP session                           |
| `binary`                            | Set the mode of file transfer to *binary*      |
|                                     | *(Provides less chance of transmission error)* |
| `cd`, `ls`, `mkdir`, `pwd`, `rmdir` | Unix operations on remote machine              |
| `delete`                            | Unix `rm` operation on remote machine          |
| `lcd`                               | Unix `cd` operation on local machine           |
| `put` *FILE*                        | Copy 1 file from local to remote               |
| `mput` *FILES* (ex: `mput *`)       | Copy multiple files from local to remote       |
| `get` *FILE*                        | Copy 1 file from remote to local               |
| `mget` *FILES* (ex: `mget*`)        | Copy multiple files from remote to local       |
-->

<h2 id="automating-ftp-logins-for-specific-ips">Automating FTP logins for specific IPs&nbsp;<a class="headline-hash no-text-decoration" href="#automating-ftp-logins-for-specific-ips">#</a></h2>


<p>If you find yourself logging into a specific <em>MACHINE</em> too frequently, and if you want to save yourself from having to enter the username and password each time, you can save those credentials to your <code>~/.netrc</code> file. See the example at the end of this post.</p>
<p>If that file does not exist, then create it, and <strong>remember to set its permission to 600</strong>.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">touch ~/.netrc
</span></span><span class="line"><span class="cl">chmod <span class="m">600</span> ~/.netrc
</span></span></code></pre></div><p>If the permissions are not set so, you will get this ftp error:</p>
<pre tabindex="0"><code>Error - .netrc file not correct mode.
Remove password or correct mode.
</code></pre>
<h3 id="ignore-the-credentials-in-netrc">Ignore the credentials in <code>.netrc</code>&nbsp;<a class="headline-hash no-text-decoration" href="#ignore-the-credentials-in-netrc">#</a></h3>


<p>But at times, you might need to manually log into a machine with a different set of credentials than the one saved in the <code>~/.netrc</code>. To do so, run <code>ftp</code> with the <code>-n</code> option. And then use the <code>quote USER</code> and <code>quote PASS</code> commands to pass in the username and password.</p>
<pre tabindex="0"><code>&gt; ftp -n &lt;machine&gt;
ftp&gt; quote USER &lt;username&gt;
ftp&gt; quote PASS &lt;password&gt;
</code></pre>
<h3 id="commenting-out-stuff-in-netrc">Commenting out stuff in <code>.netrc</code>&nbsp;<a class="headline-hash no-text-decoration" href="#commenting-out-stuff-in-netrc">#</a></h3>


<p>Unfortunately, <code>.netrc</code> does not seem to have a comment syntax. But this hack works ..</p>
<p>Using the <code>#</code> character quickly followed by an FTP command <em>foo</em> (no space, ex: <code>#foo</code>) is one way to &ldquo;comment out&rdquo; lines with valid .netrc keywords.</p>
<blockquote>
<p>You cannot have such &lsquo;comments&rsquo; after valid .netrc keywords are used.</p>
</blockquote>
<p>So if you need to comment out a set of logins and passwords, do that <strong>before</strong> the first valid set of uncommented login credentials. See below for an example of that.</p>

<h2 id="an-example-netrc">An Example <code>~/.netrc</code>&nbsp;<a class="headline-hash no-text-decoration" href="#an-example-netrc">#</a></h2>


<pre tabindex="0"><code>#machine foo.bar.com
#login username1
#password pAsSw0rd1

machine foo.bar.com
login username2
password pAsSw0rd2
</code></pre>
<h2 id="references">References&nbsp;<a class="headline-hash no-text-decoration" href="#references">#</a></h2>


<ul>
<li><a href="https://www.cs.colostate.edu/helpdocs/ftp.html">Basic FTP Commands</a> - Colorado State Univerity</li>
<li><a href="https://unix.stackexchange.com/a/28440/57923">Use configuration file for ftp with auto login enabled upon initial connection</a> - <em>unix.stackexchange</em></li>
<li><code>man ftp</code>, <code>man netrc</code></li>
</ul>]]></content><category scheme="https://scripter.co/categories/ftp" term="ftp" label="ftp"/></entry></feed>