Python self-writing software (1)

Because of the boredom of the epidemic, I learned Python by myself during the winter vacation

The big guys in the group are all learning C ++, I have read the java book, and I do n’t know if my notebook   ( Web view ) can be opened.

There are many Python libraries, the syntax is simple, and then I have learned some self-contained libraries and third-party libraries. I may learn matplotlib or numpy later.

First attach the address to myftp (github address)

This implements the command line file transfer, using the paramiko library (cmd download command: pip install -i https://pypi.douban.com/simple paramiko)

1  import time
 2  from get import ssh_server_get
 3  from put import ssh_server_put
 4  
5 ip_or_hostname = input ( " $ Please enter the IP or host name of the target server: \ n $ " )
 6  print ( " Please check whether the server port 22 is open (not configured ssh service needs to be configured, details, please Baidu) " )
 . 7  # the TODO Tip 
8  # command line parameters to the module 
. 9 the time.sleep (2 )
 10 username = iNPUT ( " $ enter username: \ n-$ " )
 . 11 Time .sleep (2 )
12 password = input ( " $ Please enter the login password: \ n $ " )
 13 time.sleep (2 )
 14 action = input ( " $ Please select the operation to perform: g / p: \ n $ " )
 15  while ( not (action == " g " )) and ( not (action == " p " )):
 16      action = input ( " $ input error, please re-enter: g / p \ n $ " )
 17 time.sleep (2 )
 18  print ( " Your operation is:% s   "% Action)
 19  # If you do not enter a default address is 
20  # with command-line parameters to the module 
21  IF Action == " G " :
 22      remote_address the INPUT = ( " address the need to download files $ input from the target server: \ n $ " )
 23      while remote_address is None:
 24          remote_address = input ( " $ Please re-enter, not empty: \ n $ " )
 25      address = input ( " $ Enter the file storage address obtained (if it is empty, it is the current directory address) : \ n $ " )
 26      print ( " Executing operation-% s   "% action)
 27      ssh_server_get (ip_or_hostname, username, password, address, remote_address)
 28  
29  elif action == " p " :
 30      address = input ( " $ Enter the address of the file to upload: \ n $ " )
 31      while address is None :
 32          address = input ( " $ Please re-enter, not empty: \ n $ " )
 33      remote_address = input ( " $ Enter the address of the target server to store the file (if it is empty, the default address \ home \ yourhostname): \ n $ " )
 34      print ( " Executing operation-% s  " % action)
35     ssh_server_put(ip_or_hostname, username, password, address, remote_address)
36 
37 time.sleep(2)
38 print("操作完成")

Here is to do the initialization work, because I want to do something like this software, the port number has been written as 22, because it is the command line, I originally wanted to make a progress library for dynamic animation, and I do n’t know how to use the asyncio coroutine. Tell me how to display animation while waiting for transmission

 

 

 

import os
import sys
import paramiko
from os.path import split, join
from os import sep


def ssh_server_put(ip_or_hostname: str, username: str, password: str, address: str,
                   remote_address: str) -> None:
    transport = paramiko.Transport((ip_or_hostname, 22))
    transport.connect(username=username, password=password)
    sftp = paramiko.SFTPClient.from_transport(transport)

    if remote_address is None:
        name=username 
        file = split (address) [-1 ] 
        path = join ( ' / home ' , name, file)
         try : 
            sftp.put (address, path) 
        except Exception as e:
             print ( " Cannot connect to remote server, please check Input: " ) 
            sys.exit ( -1 ) 

    else :
         try : 
            sftp.put (address, join (remote_address, split (address) [ -1 ]))
         except Exception as e:
             print ( "Unable to connect to the remote server, please check the input: " ) 
            sys.exit ( -1 ) 
    sftp.close ()

First create the transport and then create the connection sftp

import paramiko
from os.path import split
import sys


def ssh_server_get(ip_or_hostname: str, username: str, password: str, address: str,
                   remote_address: str) -> None:
    transport = paramiko.Transport((ip_or_hostname, 22))
    transport.connect(username=username, password=password)
    sftp = paramiko.SFTPClient.from_transport(transport)
    # sftp.put("1.txt","/home/siuwhat/Desktop/1.txt")
    if address is None:
        try:
            sftp.get (remote_address, split (remote_address) [ -1 ])
         except Exception as e:
             print ( " Unable to connect to the remote server, please check the input: " ) 
            sys.exit ( -1 )
     else :
         try : 
            sftp.get ( remote_address, address + split (remote_address) [-1 ])
         except Exception as e:
             print ( " Unable to connect to the remote server, please check the input: " ) 
            sys.exit ( -1 ) 
    sftp.close ()

almost the same

Then use pyinstaller, a download link with paramiko, just change the library name, if you don't believe it, add the library name after -i

 

This is the pyinstaller command

-F package into an exe

-w (not used here) does not pop up cmd

-i Set application icon

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/otakus/p/pysoft1.html