ryanwaite28
ryanwaite28

Reputation: 2038

Python. Send Uploaded File To Remote Server

In My Flask App, i want to upload a file to a remote server.

i tried this code but i get an error

import subprocess 

import os

c_dir = os.path.dirname(os.path.abspath(__file__))
myfile = open(c_dir + '\\cape-kid.png')

p = subprocess.Popen(["scp", myfile, destination])
sts = os.waitpid(p.pid, 0)

this was just a test file. there's an image in the same directory as my test python file. the error said:

Traceback (most recent call last): File "C:\Users\waite-ryan-m\Desktop\remote-saving\test-send.py", line 20, in p = subprocess.Popen(["scp", c_dir + '\cape-kid.png', 'destination']) File "C:\Users\waite-ryan-m\Desktop\WPython\WinPython-64bit-2.7.12.1Zero\python-2.7.12.amd64\lib\subprocess.py", line 711, in init errread, errwrite) File "C:\Users\waite-ryan-m\Desktop\WPython\WinPython-64bit-2.7.12.1Zero\python-2.7.12.amd64\lib\subprocess.py", line 959, in _execute_child startupinfo) WindowsError: [Error 2] The system cannot find the file specified

Upvotes: 1

Views: 640

Answers (1)

nidomiro
nidomiro

Reputation: 830

With open() you open an file to read or write on it. What you want is to concatinate the string and use this as parameter for scp. Maybe the file you want to copy also doesn't exist - have you tried printing the path you constructed and checking it manually? And have you defined destination anywhere? This message could also mean, that the system cannot find scp.

Upvotes: 1

Related Questions