2017-08-28 13 views
-1

ftp.dir() & ftp.retrlines('LIST')の違いは何ですか?私はFTPに関する小さなスニペットを書いて両方をテストし、同じ結果を得ています。pythonのftp.dir()とftp.retrlines( 'LIST')の違いは何ですか?

UNIX/LINUXでPythonバージョン3を使用しているときに実際に違いはありますか?

#!/usr/bin/env python 
import ftplib 
import getpass 

def getFTP(): 

    # username = getpass.getuser() --> This doesn’t prompt the user for their username. Instead, it uses the current user’s login name, 
    # according to the user’s shell environment 
    site_address = input('Please Enter the FTP address: ') 
    username = input('Please Enter your username: ') 
    password = getpass.getpass('Please Enter your password to login: ') 

    with ftplib.FTP(site_address) as ftp: 
    ftp.login(username, password) 
    ftp.cwd('/home/karn/') 
    print(ftp.getwelcome()) 
    print ("-----------------------------------------------") 
    print('Your Current Directory Is:', ftp.pwd()) 
    print('Listing the content of the Current Dir please wait...... ') 
    print ("-----------------------------------------------") 
    #ftp.dir() 
    ftp.retrlines('LIST')    # list directory contents 
    print ("------------------------------------------------------------") 
    download = input('Please Enetr the File name you want to Download: ') 
    print ("------------------------------------------------------------") 
    ftp.retrbinary('RETR ' + download, open(download, 'wb').write) 
    print('File Download is Successful.') 
    ftp.quit() 
    print('Goodbye!') 

getFTP() 
+0

は、ドキュメントを読んで記述する必要がありますか? 'dir()' - * LISTコマンドで返されたディレクトリリストを生成し、標準出力に出力する* ... –

+0

内部的に '' dir''が '' retrlines(LIST) ''を呼び出すので違いはありません –

+0

@ cricket_007 ..それは私が知っている、私はちょうど質問が別の上の任意の特定のベニフィートを持っているかどうか尋ねた..私はドキュメントを介して行った.. – rockypy17

答えて

0

dir() is a shortcut methodこれは、リストするディレクトリのオプションパラメータをとります。

そうしないと、あなたはLIST /path

関連する問題