简体   繁体   中英

How to Download a file to a specific path in the server : Python

How to download a file through http on to a local folder on my server in jython(or python)

The below code might work

os.chdir("/path/to/change/to")
from urllib2 import urlopen
f = urlopen("http://some.server/some/directory/some.file")

But for this my Current working directory is changed.I want to be in the current working directory and download the file to any given path on my Server.

Any help ?

How about urllib.urlretrieve

import urllib
urllib.urlretrieve('http://python.org/images/python-logo.gif', '/tmp/foo.gif')

使用open(..., 'wb')打开你喜欢的地方文件, urllib2.urlopen()打开网络资源, shutil.copyfileobj()从一个到另一个复制。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM