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

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? :confused:

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

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.

Try screen, it works. 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.
Wikipedia has a good article.

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).

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.

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:/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.

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.