Search Everything via ETP

ETP簡單來說就是FTP+延伸指令。所以,外部程式若要利用ETP來搜尋檔案的話,需要基本的FTP支援。

  • 預設port: 5485
  • mode: PASV

Query syntax

QUERY <SP> <offset> <SP> <max> <SP> <match_case> <SP> <match_whole_word> <SP> <match_path> <SP> <search_string> <CRLF>
  • offset is the scroll bar offset (use 0 for all items)
  • max is the maximum number of visible items in the list. (use 0xffffffff for all items)
  • match_case can be non-zero for enabled, zero for disabled.
  • match_wholeword can be non-zero for enabled, zero for disabled.
  • match_path can be non-zero for enabled, zero for disabled.
  • search_string can be any number of parameters. 
Query reply
200 <SP> <offset> <SP> <count> <SP> <numfolders> <SP> <numfiles> <CRLF>
  • offset is the index offset of the first result.
  • count is the number of results that follow
  • numfolders is the total number of folders.
  • numfiles is the total number of files.
"count" results follow:
<full_path_name> <CRLF>
  • full path and file name of folder or file 

Python Example Code
def search(q, maxResult=1000, match_case=False, match_whole_word=False, match_path=True):
    # Query
    cmd = "QUERY 0 %d %d %d %d %s"%(maxResult, match_case, match_whole_word, match_path, q)

    # Query response offset control
    resp = ftp.sendcmd(cmd)
    code, offset, count, numfolders, numfiles = resp.split()

    results = []
    for i in range(int(count)):
        line = ftp.getmultiline().decode("UTF-8")
        results.append(line)

    return int(numfolders), int(numfiles), results


Reference:

沒有留言:

張貼留言