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

≯℡__Kan透↙ 提交于 2019-12-20 02:45:28

问题


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 ?


回答1:


How about urllib.urlretrieve

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



回答2:


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.



来源:https://stackoverflow.com/questions/6373094/how-to-download-a-file-to-a-specific-path-in-the-server-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!