I am new to Python and it is first post. Want to upload a TXT file to server, (as of now, it is local host).Every time, I run the script, the local file uploaded and updated on server. I am using Requests module
import requests, time
url ='http://192.168.49.205/test/database/data.txt' # where i want to write
files = {'file':('data.txt','C:\Python27\data.txt','rb')}
#r = requests.post(url,files=files) # this works too
r= requests.post('http://192.168.49.205/test/database/data.txt',
data={'upload_type': 'standard', 'upload_to': '0'},files=files)
print r.status_code
print r.text
data.txt is not updated. Just seeing old data (I put some values when file created).I am not using any Forms in PHP or HTML. Is it possible to upload with method?
Believe,I got some clarity after posting the question. Now, there is PHP file on server side listening to client. Here is the "post.php". So, this will replace the text file on Client side. PHP file get the Name, Task, Value from client and post to "a.txt" on server (local)
<?php
if(isset($_GET["Name"])){
$name=$_GET["Name"];
}
if(isset($_GET["Task"])){
$task=$_GET["Task"];
}
if(isset($_GET["Value"])){
$value=$_GET["Value"];
}
$f=fopen("a.txt","w") or exit("Unable to open file!");
fwrite($f,$name);
fwrite($f," ");
fwrite($f,$task);
fwrite($f," ");
fwrite($f,$value);
fclose($f);
?>`
So now Requests look like this
import requests, time
url = 'http://192.168.49.205/test/test.php'
post_data = {'Name':'job','Task':'008','Value':'8'}
r= requests.post('http://192.168.49.205/test/post.php', data= post_data)
print r.status_code
print r.text
Stil the values is not reaching "a.txt". What i am missing? Please advise!
http://192.168.49.205/test/database/data.txtacceptPOSTrequests? What kind of service is listening there?