I have a simple form where user inputs remote host, username and password of their server. I process the form using upload_file view in my views.py. I want to run the following command with the input provided by the user:
rsync --list-only username@serveraddress
To run the following command user must type password and after successful authentication the file will be listed. I already take password input from the user however I don’t know how to use it. After immediately running the above command password must be inputted in the terminal. How do I implement the same thing in Django? Here’s my views.py:
def upload_file(request):
if request.method == 'POST':
#session_name = request.POST.get['session']
url = request.POST.get('hostname', False)
username = request.POST.get('username', False)
source = str(username) + "@" + str(url)
command = subprocess.Popen(['rsync', '--list-only', source], stdout=subprocess.PIPE).communicate()[0]
return render_to_response('thanks.html', {'res':result, 'res1':command}, context_instance=RequestContext(request))
else:
pass
return render_to_response('form.html', {'form': 'form'}, context_instance=RequestContext(request))
I think the title of this question is a bit miseading, maybe it should be “How to pass server password…”. Anyways, if I understand correctly, you can set the environment variable RSYNC_PASSWORD:
beware, environment variables may be visible to other system users
if that scares you you could use the rsync option
--password-file(see rsync manual)one more nit: by specifying
envcaller environment is not passed to rsync process anymore.