Get file list from FTP server

I am trying to get a list of all the files that we have on the server (in particular, every PDF file that we have). I tried using a generic command and looking for files. It worked to some extent, as in, I got a list of each pdf file that we had there, but in no way exported the results (we have more than 100,000 files)

I tried using a bash script to get the information, but I am not very good at Linux, and I really don't know what I'm doing.

My script looks like this:

#!/bin/bash hostname="<host>" ftp -i -nv $hostname << EOF user <username> <password> ls -R EOF 

Running above script i get

 ?Invalid command 501 Illegal PORT command ftp: bind: Address already in use 221 Goodbye 

Any help or guidance on what to look for would be greatly appreciated.

+7
source share
4 answers

Try setting ftp to use PASV (passive) mode for data transfer. This is done using the -p switch.

I'm not sure if you can make a recursive list of files with this ftp client. ls -R in my case just gave a list of files and directories in the current working directory. Perhaps a recursive list of FTP directories in the / bash shell in a single session (using cURL or ftp) will help you.

+4
source

Curled, it’s convenient
curl ftp:// yourftpserver/dir/ --user username:password

+26
source

ncftpls ftp://yourftpserver/dir/*.pdf

Please note that templates such as *.pdf , etc. in the above command, work as expected.

For recursive use -R . For more options, see man ncftpls .

ncftpls provided by the ncftp package. For RHEL, this package is available in the epel .

+4
source
 curl ftp://user: password@ <ip>/path/ 

Last / is required if it is a directory. This worked in curl version 7.29.0

+3
source

All Articles