개발 저장소/개발 지식 저장소
[Python] 외부 서버의 NAS 연동(SSH Client 활용)
이거비버
2023. 5. 3. 15:59
반응형
# SFTP 클라이언트 생성
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect('NAS의 url', port='NAS의 port', username='username', password='password')
sftp_client = ssh_client.open_sftp()
# NAS의 파일 리스트 출력
print(sftp_client.listdir('/web/media/'))
# 파일 업로드
sftp_client.put('/path/to/local/file', '/mnt/nas/remote/file')
# 파일 다운로드
sftp_client.get('/mnt/nas/remote/file', '/path/to/local/file')
# SFTP 클라이언트 종료
sftp_client.close()
반응형