[英]Python equivalent of this Curl command
我正在嘗試使用python來下載文件,模仿與此curl命令相同的行為:
curl ftp://username:password@example.com \
--retry 999 \
--retry-max-time 0
-o 'target.txt' -C -
在python中看起來如何?
我調查過的事情:
請求:不支持ftp
Python-wget:不支持下載簡歷
request-ftp:不支持下載恢復
fileDownloader:損壞(?)
我猜想一個人需要從頭開始構建它,並使用pycurl或urllib2或類似的東西進行低級構建。
我正在嘗試在python中創建此腳本,我感到迷路。我應該從python子進程中調用curl嗎?
任何指向寫入方向的信息將不勝感激
您可以使用python的內置ftplib
這是代碼:
from ftplib import FTP
ftp = FTP('example.com', 'username', 'password') #logs in
ftp.retrlines() # to see the list of files and directories ftp.cwd('to change to any directory')
ftp.retrbinary('RETR filename', open('Desktop\filename', 'wb').write) # start downloading
ftp.close() # close the connection
支持自動恢復。 我什至嘗試關閉wifi並檢查下載是否正在恢復。
您可以參考/Python27/Lib/ftplib.py以獲得默認的GLOBAL_TIME_OUT設置。
有這個庫可以從ftp服務器下載文件
下載文件
downloader = fileDownloader.DownloadFile(‘http://example.com/file.zip’, “C:UsersusernameDownloadsnewfilename.zip”, (‘username’,’password’))
downloader.download()
恢復下載
downloader = fileDownloader.DownloadFile(‘http://example.com/file.zip’, “C:UsersusernameDownloadsnewfilename.zip”, (‘username’,’password’))
downloader.resume()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.