I found a solution

step one: install the Paramiko library on the application server 
(SERVER_ONE)

step two: import the paramiko library

step three: use the "putfo" method

here is an example

def file_upload():
import paramiko
form = FORM(
DIV(
INPUT(
_type = "file",
_name = "file",
)
),
DIV(
INPUT(
_type = "submit",
_value = "UPLOAD IMAGE"
)
),
_enctype="multipart/form-data",
)
if (form.process().accepted):
client = paramiko.SSHClient()
client.load_system_host_keys()
t = paramiko.Transport("www.server_two_url.com", 22)
t.connect(username = SERVER_TWO_LOGIN_STRING, password = 
SERVER_TWO_PASSWORD_STRING)          # for example:          
t.connect(username = "root", password = "abc123")
sftp = paramiko.SFTPClient.from_transport(t)
sftp.putfo(form.vars.file.file, "/root/auden.jpg")
sftp.close()
t.close()
return dict(
form = form,
)

THAT WORKS FINE!  (on SERVER_TWO server using WinSCP I go to the /root 
folder on the VPS and there is the file)






On Monday, October 14, 2019 at 8:23:25 AM UTC-5, Auden RovelleQuartz wrote:
>
> Please let me know how to do this
>
> SERVER_ONE: this is the application server
> SERVER_TWO: this is the file storage server
>
> The objective is to
>
> >>> have the user select a file via a form (this is via a Web2py app 
> running on SERVER_ONE)
> >>> when user clicks the submit button, the file is posted to an API 
> endpoint on SEVER_TWO
> >>> the web2py app on SERVER_TWO then saves the file to disk
>
>
> Here is my code for SERVER_ONE:
>
> def file_upload():
> form = FORM(
> DIV(
> INPUT(
> _type = "file",
> _name = "file",
> requires = IS_LENGTH(MAX_IMAGE_UPLOAD_SIZE, MIN_IMAGE_UPLOAD_SIZE),
> )
> ),
> DIV(
> INPUT(
> _type = "submit",
> _value = "UPLOAD IMAGE"
> )
> ),
> _method = "post",
> _enctype="multipart/form-data",
> )
> if (form.process().accepted):
> r = requests.post(
> SERVER_TWO_APP_BASE_URL + "/default/get_file", 
> files={'file': form.vars.file.file.read()}
> ) 
> return dict(
> form = form,
> )
>
>
>
> Here is my code for in default.py controller of SERVER_TWO:
>
> import requests 
>
> def get_file():
> try:
> file = request.files['file']
> file.save('', file.filename)
> except Exception as e:
> with open("_probe_20191013_001", "w") as f:
> f.write(str(e))
> with open("_probe_20191013_002", "w") as f:
> f.write("\n\nthis is a test\n\n")
> f.write(str(request))
> return dict()
>
> ==============================================================
>
> The file is not getting saved on SERVER_TWO
>
> does anyone have any advice on how to accomplish that?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/ee5f2127-18b8-4840-a298-a9d806100710%40googlegroups.com.

Reply via email to