Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Learning Python Networking
  • Toc
  • feedback
Learning Python Networking

Learning Python Networking

By : Dr. M. O. Faruque Sarker, Samuel B Washington, Sam Washington
3.7 (7)
close
Learning Python Networking

Learning Python Networking

3.7 (7)
By: Dr. M. O. Faruque Sarker, Samuel B Washington, Sam Washington

Overview of this book

If you're a Python developer or a system administrator with Python experience and you're looking to take your first steps in network programming, then this book is for you. Basic knowledge of Python is assumed.
Table of Contents (12 chapters)
close
10
A. Working with Wireshark
11
Index

Transferring files through SFTP

SSH can be used effectively for securely transferring files between two computer nodes. The protocol used in this case is the secure file transfer protocol (SFTP). The Python paramiko module will supply the classes required for creating the SFTP session. This session can then perform a regular SSH login.

ssh_transport = paramiko.Transport(hostname, port)
ssh_transport.connect(username='username', password='password')

The SFTP session can be created from the SSH transport. The paramiko's working in the SFTP session will support the normal FTP commands such as get().

 sftp_session = paramiko.SFTPClient.from_transport(ssh_transport)
 sftp_session.get(source_file, target_file)

As you can see, the SFTP get command requires the source file's path and the target file's path. In the following example, the script will download a test.txt file, which is located on the user's home directory, through SFTP:

#!/usr/bin/env python3

import...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete