1.首先要先安裝FTP伺服器套件-pyftpdlib,命令如下:
pip3 install pyftpdlib
2.設定使用者帳號和密碼,帳號設為demo,密碼是1234,命令如下:
python -m pyftpdlib --user=demo --password=1234
3.可以再開啟另一個命令提示字元,執行FTP伺服器的功能,其命令如下:
curl --user demo:1234 ftp://127.0.0.1:2121/
4.FTP用戶端的程式碼:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import ftplib conn = ftplib.FTP() conn.connect('127.0.0.1', 2121) conn.login('demo','1234') data = [] conn.dir(data.append) conn.quit() for line in data: print ("-", line) |
- drwxrwxrwx 1 owner group 0 Nov 24 2019 .AndroidStudio3.5
- drwxrwxrwx 1 owner group 0 Aug 26 2020 .LINE
- drwxrwxrwx 1 owner group 0 Aug 26 2020 .QtWebEngineProcess
- drwxrwxrwx 1 owner group 0 Feb 13 2020 .anaconda
- drwxrwxrwx 1 owner group 4096 Nov 24 2019 .android
- -rw-rw-rw- 1 owner group 243 Jul 11 2020 .bash_history
- drwxrwxrwx 1 owner group 0 Oct 04 00:13 .cache
- drwxrwxrwx 1 owner group 0 Jul 13 2020 .conda
沒有留言:
張貼留言