简体   繁体   English

如何将文件下载到服务器中的特定路径:Python

[英]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) 如何通过http将文件下载到我的服务器上的本地文件夹中jython(或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 urllib.urlretrieve怎么样?

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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