ftp nlst 命令在 Python 中运行,但不在 Windows 命令行中运行

问题描述 投票:0回答:1

我通过 python 公开了一个 API,通过 ftplib 连接到我的 ftp 服务器:

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

它通过 NLST 方法成功检索文件列表。

当我

通过 Windows 命令行连接到我的 ftp 服务器时,我无法运行 NLST 方法:

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>

    是因为 ftplib 和 Windows Command Line 基本上是两个不同的 ftp 客户端,并且实现了不同的方法吗?
  • 如果上述情况成立,那么 Windows 命令行中的 nlst 相当于什么?
python command-line ftp windows-console
1个回答
0
投票

NLST

 是 FTP 协议命令。

与任何其他协议(或其他协议)的任何其他实现一样,不同的(FTP)客户端/库将具有不同的 API 用于访问功能:

    ftplib 有
  • FTP.nlst()
     方法
  • Windows
  • ftp
     客户端有 
    ls
     命令
请注意,两者都不是简单地映射到

NLST

 FTP 命令,因为 FTP 协议中的所有文件传输和列表都是复杂的操作。它们涉及多个命令并打开单独的传输连接。 
NLST
 只是整个操作的一个(也是最重要的)部分。

© www.soinside.com 2019 - 2024. All rights reserved.