我想将照片从计算机上传到ec2,我知道您可以使用s3和boto3库,但这不适合我,因为照片本身应该在ec2上(在此处处理)并下载他们在s3上使用python会花费太多时间(我想在ec2上上传和处理照片,但是将它们下载并上传到s3则需要额外的时间)
我想要的例子
client = boto3.client('ec2')
client.upload_file(path_in_my_computer)
答案 0 :(得分:2)
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('... .compute.amazonaws.com', username='ubuntu', password='',
key_filename='D:\style_transfer.pem')
# Setup sftp connection and transmit this script
print("copying")
sftp = client.open_sftp()
sftp.put('1.jpg', '/home/ubuntu/1.jpg')
sftp.close()
答案 1 :(得分:1)
是的,您可以使用scp
:
示例:
scp -i my_key.pem /Path/where/the/photo/is/located ec2-user@your-amazon-instance