pythoncommand-lineftpwindows-console

ftp nlst command runs in Python, but not in Windows Command Line


I have exposed an API via python that connects to my ftp server via ftplib:

from ftplib import FTP    

@app.route('/api/ftp/list', methods=['GET'])
def ftp_list():
    remote_dir = request.args.get('remote_dir', '/')

    try:
        ftp = ftp_connect()
        #ftp.cwd(remote_dir)
        files = ftp.nlst()
        ftp.quit()
        return jsonify({'files': files}), 200
    except Exception as e:
        return jsonify({'error': str(e)}), 500

It retrieves the list of files via the NLST method successfully.

When I connect to my ftp server via Windows Command Line, I can't run the NLST method:

ftp> dir
200 'PORT' OK.
125 Data connection already open; starting 'BINARY' transfer.
-rw------- 1 tester users         95 Sep 19 20:34 testfile.txt
226 Transfer complete.
ftp: 67 bytes received in 0.00Seconds 67000.00Kbytes/sec.
ftp> nlst
Invalid command.
ftp>

Solution

  • NLST is FTP protocol command.

    As with any other implementation of any other protocol (or whatever), different (FTP) client/libraries will have different API for accessing the functionality:

    Note that neither is simply mapped to NLST FTP command, as all file transfers and listings in FTP protocol are complex operations. They involve multiple commands and opening separate transfer connection. The NLST is just one (and the most significant) part of the whole operation.