GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ssh2-python/examples/scp_write.py at buffer_write · 7Learnings/ssh2-python

Expand file tree

/

scp_write.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
executable file
·
54 lines (41 loc) · 1.6 KB
/

scp_write.py

Copy path

File metadata and controls

executable file
·
54 lines (41 loc) · 1.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python
"""Example script for SCP write"""
from __future__ import print_function
import argparse
import socket
import os
import pwd
import sys
from datetime import datetime
from ssh2.session import Session
USERNAME = pwd.getpwuid(os.geteuid()).pw_name
parser = argparse.ArgumentParser()
parser.add_argument('source', help="Source file to copy")
parser.add_argument('destination', help="Remote destination file to copy to")
parser.add_argument('--host', dest='host',
default='localhost',
help='Host to connect to')
parser.add_argument('--port', dest='port', default=22, help="Port to connect on", type=int)
parser.add_argument('-u', dest='user', default=USERNAME, help="User name to authenticate as")
def main():
args = parser.parse_args()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((args.host, args.port))
s = Session()
s.handshake(sock)
s.agent_auth(args.user)
fileinfo = os.stat(args.source)
chan = s.scp_send64(args.destination, fileinfo.st_mode & 0o777, fileinfo.st_size,
fileinfo.st_mtime, fileinfo.st_atime)
print("Starting SCP of local file %s to remote %s:%s" % (
args.source, args.host, args.destination))
now = datetime.now()
with open(args.source, 'rb') as local_fh:
for data in local_fh:
chan.write(data)
taken = datetime.now() - now
rate = (fileinfo.st_size / (1024000.0)) / taken.total_seconds()
print("Finished writing remote file in %s, transfer rate %s MB/s" % (
taken, rate))
if __name__ == "__main__":
main()
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.