Code:
import pygame
import pygame.camera
import requests
import paramiko
import os
import sys
pygame.camera.init()
cam = pygame.camera.Camera("/dev/video0",(640,480))
cam.start()
img = cam.get_image()
pygame.image.save(img,"image.jpg")
source = r'/home/pi/file/image.jpg'
dest = r'/home/pi/file/image.jpg'
hostname = '192.168.1.220'
port = 22 # default port for SSH
username = 'pi'
password = 'raspberry'
try:
t1 = paramiko.Transport((hostname, port))
t1.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(t1)
sftp.put(source, dest)
finally:
t1.close()
SFTP
Communication (File Transfer) between Raspberry Pi and other system via
Ethernet or WiFi:
Code:
#import base64
import binascii
import requests
import paramiko
import os
import sys
filename = 'filename.txt'
fh=open('filename.txt', 'ab')
fh.close
source = r'/home/pi/file/filename.txt'
dest = r'/home/pi/file/filename.txt'
hostname = '192.168.0.210'
port = 22 # default port for SSH
username = 'pi'
password = ‘raspberry’
try:
t1 = paramiko.Transport((hostname, port))
t1.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(t1)
sftp.put(source, dest)
finally:
t1.close()
0 comments:
Post a Comment
if you have any doubt please let me know