尝试使用 ssh 将文件从 Internet 上传到我的服务器。有以下代码可以很好地上传本地文件,但我不知道还要做什么才能让图片字节对象上传。
from io import BytesIO
import requests
import pysftp
url = 'https://vignette.wikia.nocookie.net/disney/images/d/db/Donald_Duck_Iconic.png'
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
response = requests.get(url)
netimage = BytesIO(response.content) #imagefromurl
srv = pysftp.Connection(host="12.34.567.89", username="root123",
password="password123",cnopts=cnopts)
with srv.cd('/var/www'): #srvdir
#srv.put('C:\Program Files\Python36\LICENSE.txt') #local file test
srv.put(netimage)
print('Complete')