开发者

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

开发者 https://www.devze.com 2023-03-13 05:54 出处:网络
How to download a file through http on to a local folder on my server in jython(or python) The below code might work

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 i开发者_Go百科s 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')


Use open(..., 'wb') to open the file where you like, urllib2.urlopen() to open the network resource, and shutil.copyfileobj() to copy from one to the other.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号