ncftpls - Internet file transfer program for scripts
ncftpls [options] ftp://url.style/host/path/name/
- Use a machine readable list format, if the server supports it. This requires that the server software support the MLSD extensions, and many implementations do not support these features.
- Most basic format, one item per line.
- Long list format.
- Columnized list format. This is the default list format.
- Recurse all subdirectories while listing.
- Show all files, if the server allows it (as in /bin/ls -a).
- -i XX
- Filter the listing (if the server supports it) with the wildcard XX.
- -x -XX
- List command flags to use on the remote server.
- -u XX
- Use username XX instead of anonymous.
- -p XX
- Use password XX with the username.
- -P XX
- Use port number XX instead of the default FTP service port (21).
- -d XX
- Use the file XX for debug logging.
- -t XX
- Timeout after XX seconds.
- Use regular (PORT) data connections.
- Use passive (PASV) data connections. The default is to use passive, but to fallback to regular if the passive connection fails or times out.
- -r XX
- Redial a maximum of XX times until connected to the remote FTP server.
-W XX Send raw FTP command XX after logging in. -X XX Send raw FTP command XX after each file transferred. -Y XX Send raw FTP command XX before logging out.
The -W, -X, and -Y options are useful for advanced users who need to tweak behavior on some servers. For example, users accessing mainframes might need to send some special SITE commands to set blocksize and record format information.
For these options, you can use them multiple times each if you need to send multiple commands. For the -X option, you can use the cookie %s to expand into the name of the file that was transferred.
-o XX Set advanced option XX.
This option is used primarily for debugging. It sets the value of an internal variable to an integer value. An example usage would be: -o useFEAT=0,useCLNT=1 which in this case, disables use of the FEAT command and enables use of the CLNT command. The available variables include: usePASV, useSIZE, useMDTM, useREST, useNLST_a, useNLST_d, useFEAT, useMLSD, useMLST, useCLNT, useHELP_SITE, useSITE_UTIME, STATfileParamWorks, NLSTfileParamWorks, require20, allowProxyForPORT, doNotGetStartCWD.
The purpose of ncftpls is to do remote directory listings using the File Transfer Protocol without entering an interactive shell. This lets you write shell scripts or other unattended processes that can do FTP.
The default behavior is to print the directory listing in columnized format (i.e. ls -CF), but that is not very useful for scripting. This example uses the -1 flag, to print one file per line:
$ ncftpls -1 ftp://ftp.ncftp.com/ncftp/
Better yet, try the machine readable format:
$ ncftpls -m ftp://ftp.ncftp.com/ncftp/ type=cdir;modify=20050407005654;UNIX.mode=0755 /ncftp type=pdir;modify=20010521005346;UNIX.mode=0755 / type=dir;modify=20050512221217;UNIX.mode=0755 binaries type=file;size=95832;modify=19971122045900;UNIX.mode=0644 ncftp-1.9.5.tar.gz type=file;size=192937;modify=19980320033600;UNIX.mode=0644 ncftp-2.4.3.tar.gz type=file;size=409722;modify=20050325011837;UNIX.mode=0644 ncftp-3.1.9-src.tar.bz2 type=file;size=516060;modify=20050325011837;UNIX.mode=0644 ncftp-3.1.9-src.tar.gz type=file;size=655834;modify=20050325011837;UNIX.mode=0644 ncftp-3.1.9-src.zip
Regrettably, many servers won't work with the machine redable option, since they don't support the required FTP server software extensions (MLSD) that make this possible. Also beware that the fields shown may vary, as well as the order. See the official machine readable list format documentation for details.
You can also do a remote "ls -l", by using ncftpls -l. If you want to try other flags (but be careful, the remote server may not support them), you have to use them with the -x flag. For example, if you wanted to do a remote "ls -lrt", you could do this:
$ ncftpls -x "-lrt" ftp://ftp.ncftp.com/ncftp/
If you wanted to filter the listing, say, to show just files that ended in the extension .TXT, you could try the -i flag, like this:
$ ncftpls -1 -i '*.TXT' ftp://ftp.freebsd.org/pub/FreeBSD/
Filtering may not work, since it depends on the FTP server software implementation. Here's a better way which does not depend on the server:
$ ncftpls -1 ftp://ftp.freebsd.org/pub/FreeBSD/ | grep -i '\.TXT$'
By default the program tries to open the remote host and login anonymously, but you can specify a username and password information like you can with ncftpget or ncftpput.
Note that the standard specifies that URL pathnames are are relative pathnames. For FTP, this means that URLs specify relative pathnames from the start directory, which for user logins, are typically the user's home directory. If you want to use absolute pathnames, you need to include a literal slash, using the "%2F" code for a "/" character. Examples:
$ ncftpls -u linus ftp://ftp.kernel.org/%2Fusr/src/ $ ncftpls ftp://email@example.com/%2Fetc/
ncftpls returns the following exit values:
- Could not connect to remote host.
- Could not connect to remote host - timed out.
- Transfer failed.
- Transfer failed - timed out.
- Directory change failed.
- Directory change failed - timed out.
- Malformed URL.
- Usage error.
- Error in login configuration file.
- Library initialization failed.
- Session initialization failed.
Mike Gleason, NcFTP Software.
ncftpput(1), ncftpget(1), ncftp(1), ftp(1), rcp(1), tftp(1).