[英]Python equivalent of this Curl command
I am trying to download a file using python, imitating the same behavior as this curl command: 我正在尝试使用python来下载文件,模仿与此curl命令相同的行为:
curl ftp://username:password@example.com \
--retry 999 \
--retry-max-time 0
-o 'target.txt' -C -
How would this look in python ? 在python中看起来如何?
Things I have looked into: 我调查过的事情:
Requests : no ftp support 请求:不支持ftp
Python-wget: no download resume support Python-wget:不支持下载简历
requests-ftp : no download resume support request-ftp:不支持下载恢复
fileDownloader : broken(?) fileDownloader:损坏(?)
I am guessing one would need to build this from scratch and go low level with pycurl or urllib2 or something similar. 我猜想一个人需要从头开始构建它,并使用pycurl或urllib2或类似的东西进行低级构建。
I am trying to create this script in python and I feel lost.. Should I just call curl from python subprocess ? 我正在尝试在python中创建此脚本,我感到迷路。我应该从python子进程中调用curl吗?
Any point to the write direction would be much appreciated 任何指向写入方向的信息将不胜感激
you can use python's inbuilt ftplib 您可以使用python的内置ftplib
Here is the code: 这是代码:
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
Auto resume is supported. 支持自动恢复。 I even tried turning off my wifi and checked if the download is resuming.
我什至尝试关闭wifi并检查下载是否正在恢复。
You can refer to /Python27/Lib/ftplib.py for default GLOBAL_TIME_OUT settings. 您可以参考/Python27/Lib/ftplib.py以获得默认的GLOBAL_TIME_OUT设置。
there is this library for downloading files from ftp server 有这个库可以从ftp服务器下载文件
fileDownloader.py fileDownloader.py
to download the file 下载文件
downloader = fileDownloader.DownloadFile(‘http://example.com/file.zip’, “C:UsersusernameDownloadsnewfilename.zip”, (‘username’,’password’))
downloader.download()
to resume download 恢复下载
downloader = fileDownloader.DownloadFile(‘http://example.com/file.zip’, “C:UsersusernameDownloadsnewfilename.zip”, (‘username’,’password’))
downloader.resume()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.