I am trying to send a file using a POST request, which is then forwarded to a server using paramiko. I have the following code:
@app.route("/", methods=['GET', 'POST'])
def upload():
file = request.files['file']
try:
gethostbyname("servername")
except gaierror:
print(gaierror)
exit()
port = 22
if request.method == 'POST':
filePost = request.args.get('filename')
transport = paramiko.Transport("servername", port))
try:
transport.connect(username="user",password="password", hostkey=None)
sftp = paramiko.SFTPClient.from_transport(transport)
except paramiko.ssh_exception.AuthenticationException as e:
print(e)
exit()
path = '/home/'+file.filename
try:
sftp.put(file, path)
except Exception as e:
print(e)
Unfortunately nothing is uploaded. I'm afraid I have to save the file that comes from the POST request first. Is it possible to work around this? Or am I missing something?
the key/value from my post request (using Postman):
key:file
value:test.txt