How to upload a file at a specific path on the server: Python

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

The code below may 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 has been changed. I want to be in the current working directory and upload the file at any path on my server.

Any help?

+3
source share
2 answers

How about urllib.urlretrieve

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

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

+1
source

All Articles