# FTP in linux shell: how to list directory contents on the computer (\*not\* the server)

**URL:** <https://boards.straightdope.com/t/ftp-in-linux-shell-how-to-list-directory-contents-on-the-computer-not-the-server/558570>\
**Category:** Factual Questions\
**Created:** [October 27, 2010, 7:04pm UTC](https://boards.straightdope.com/t/ftp-in-linux-shell-how-to-list-directory-contents-on-the-computer-not-the-server/558570 "2010-10-27T19:04:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Engywook](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@Engywook](https://boards.straightdope.com/u/Engywook)\
**Post date:** [October 27, 2010, 7:04pm UTC](https://boards.straightdope.com/t/ftp-in-linux-shell-how-to-list-directory-contents-on-the-computer-not-the-server/558570/1 "2010-10-27T19:04:05Z")

</div>

I can’t believe I have to ask this, but it has been more than ten years since I’ve done an FTP with a command line. So here goes:

I know that **ls** lists the files in the current directory on the server, **cd** changes directories, and so on.

But how do I find out about the active directory on the computer? I don’t see a command anywhere I’ve looked. I ask because I am trying to upload a rather large file this way, and I haven’t the foggiest where it should be on the computer, or how to get ftp to pull from the directory where the file is.

Make any sense? 😕

---

<div class="post-metadata">

**Author:** ![Quartz](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/quartz/32/267_2.png) [@Quartz](https://boards.straightdope.com/u/Quartz)\
**Post date:** [October 27, 2010, 7:16pm UTC](https://boards.straightdope.com/t/ftp-in-linux-shell-how-to-list-directory-contents-on-the-computer-not-the-server/558570/2 "2010-10-27T19:16:54Z")

</div>

Can’t you bring up another window and get a directory that way? To change the local directory within ftp you use **lcd**.

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [October 27, 2010, 7:17pm UTC](https://boards.straightdope.com/t/ftp-in-linux-shell-how-to-list-directory-contents-on-the-computer-not-the-server/558570/3 "2010-10-27T19:17:04Z")

</div>

Why don’t you just open a second terminal window (or ctrl-Z to switch to a shell) and use your local shell’s normal directory-browsing commands?

AFAIK commandline FTP does not have an option for browsing the local directory tree. You’re supposed to know where stuff is already.

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [October 27, 2010, 7:29pm UTC](https://boards.straightdope.com/t/ftp-in-linux-shell-how-to-list-directory-contents-on-the-computer-not-the-server/558570/4 "2010-10-27T19:29:08Z")

</div>

[Try screen, it works.](http://www.gnu.org/software/screen/) screen multiplexes a single virtual terminal (xterm, Linux console, etc.) and allows you to do things like copy-and-paste, keep sessions running on a remote host after you disconnect, and even split the screen into multiple independent panes, all entirely from the keyboard and, unless you’re using it in an xterm, without needing to launch X. It might well already be installed on your system; type ‘which screen’ or ‘info screen’ into a command prompt to find out.

[The instruction manual is very useful.](http://www.gnu.org/software/screen/manual/screen.html)  
[Wikipedia has a good article.](http://en.wikipedia.org/wiki/GNU_Screen)

---

<div class="post-metadata">

**Author:** ![Engywook](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@Engywook](https://boards.straightdope.com/u/Engywook)\
**Post date:** [October 27, 2010, 7:32pm UTC](https://boards.straightdope.com/t/ftp-in-linux-shell-how-to-list-directory-contents-on-the-computer-not-the-server/558570/5 "2010-10-27T19:32:54Z")

</div>

> [@friedo](#):
>
> AFAIK commandline FTP does not have an option for browsing the local directory tree. You’re supposed to know where stuff is already.

Kind of tough when you can’t see a local directory. I’m beginning to wonder if the “local” directory is not really local.

**pwd** , which gives current location (supposedly on local) says that I am at **/**. But clearly this is not referring to the root directory on the hard drive. If I type **lcd public\_html** , I get this message:

**OK. Current directory is /public\_html**.

So it looks like FTP thinks the local directory is the same as the remote directory???

---

<div class="post-metadata">

**Author:** ![Omphaloskeptic](https://avatars.discourse-cdn.com/v4/letter/o/bcef8e/32.png) [@Omphaloskeptic](https://boards.straightdope.com/u/Omphaloskeptic)\
**Post date:** [October 27, 2010, 7:40pm UTC](https://boards.straightdope.com/t/ftp-in-linux-shell-how-to-list-directory-contents-on-the-computer-not-the-server/558570/6 "2010-10-27T19:40:56Z")

</div>

> [@Engywook](#):
>
> Kind of tough when you can’t see a local directory. I’m beginning to wonder if the “local” directory is not really local.
> 
> **pwd** , which gives current location (supposedly on local) says that I am at **/**. But clearly this is not referring to the root directory on the hard drive. If I type **lcd public\_html** , I get this message:
> 
> **OK. Current directory is /public\_html**.
> 
> So it looks like FTP thinks the local directory is the same as the remote directory???

**pwd** gives the current location on the remote server, at least with the version of FTP I’m using. Use **!\<cmd\>** to run a local command (in a subshell): **!pwd** , **!ls** , etc.; the only exception is that you use **lcd** to change the local directory ( **!cd** won’t work since the working directory reverts to its previous value when the subshell exits).

---

<div class="post-metadata">

**Author:** ![goldmund](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@goldmund](https://boards.straightdope.com/u/goldmund)\
**Post date:** [October 27, 2010, 7:46pm UTC](https://boards.straightdope.com/t/ftp-in-linux-shell-how-to-list-directory-contents-on-the-computer-not-the-server/558570/7 "2010-10-27T19:46:18Z")

</div>

> [@Engywook](#):
>
> Kind of tough when you can’t see a local directory. I’m beginning to wonder if the “local” directory is not really local.
> 
> **pwd** , which gives current location (supposedly on local) says that I am at **/**. But clearly this is not referring to the root directory on the hard drive. If I type **lcd public\_html** , I get this message:
> 
> **OK. Current directory is /public\_html**.
> 
> So it looks like FTP thinks the local directory is the same as the remote directory???

**pwd** within the FTP client will return the working directory on the FTP server. This can be changed with ‘cd’ as usual. **lcd** changes the local working directory, or with no arguments, will print the local working directory.

**/** won’t always refer to the root directory, in the context of an FTP server, and nowadays often will not. Most ftp servers are chrooted or otherwise restricted to one portion of the filesystem. The **/** visible via FTP is going to be the root, relative to the server’s chrooted directory.

To the OP, if you want to list files in the local directory from within the FTP client, the **!** is your friend. A ‘!’ followed by any shell command will execute that command and return its output. So, simply enter: **!ls** , **!ls -CF** , **!ls -lh** , etc. Or **!df** to check local disk space, or any other shell command.

---

<div class="post-metadata">

**Author:** ![zwede](https://avatars.discourse-cdn.com/v4/letter/z/ac91a4/32.png) [@zwede](https://boards.straightdope.com/u/zwede)\
**Post date:** [October 27, 2010, 7:47pm UTC](https://boards.straightdope.com/t/ftp-in-linux-shell-how-to-list-directory-contents-on-the-computer-not-the-server/558570/8 "2010-10-27T19:47:24Z")

</div>

FTP is fairly ancient and clunky. I prefer scp. Same syntax as the regular linux/unix cp (copy) command, except either source or destination can be on a remote system. Example:

scp /home/tom/file1 [bob@10.10.10.10](mailto:bob@10.10.10.10):/home/bob

This copies “file1” to the machine with IP address 10.10.10.10, into the directory /home/bob, and it will access 10.10.10.10 with the user bob.

You don’t have to use the IP address, you can use the name of the server also.

Good thing about scp is that the transfer is encrypted, where ftp is not.

---

<div class="post-metadata">

**Author:** ![Superfluous\_Parentheses](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Superfluous\_Parentheses](https://boards.straightdope.com/u/Superfluous_Parentheses)\
**Post date:** [October 27, 2010, 7:57pm UTC](https://boards.straightdope.com/t/ftp-in-linux-shell-how-to-list-directory-contents-on-the-computer-not-the-server/558570/9 "2010-10-27T19:57:51Z")

</div>

Personally, I prefer ncftp, which has local equivalents for all directory traversing commands that are simply the remote commands prefixed with l (as in “local”):

lls - lists local directory  
lcd - cd locally

etc.

ncftp also has bookmark/credential storage which also work with the more “scriptable” binaries ncftpput, ncftpget, ncftpls etc.
