In winter vacation, I learned Python by myself because of the boredom of epidemic situation. I started with a few lessons at random
All the big guys in the group are learning c + +. I have finished reading the java book, My notebook (Web view )I don't know if I can open it.
python has many libraries with simple syntax, and then learns some self-contained libraries and third-party libraries. Later, you may learn matplotlib or numpy. pyqt5 is still learning, but there are many wheels to realize
Attach the address first myftp(github address)
This implements command-line file transfer and uses paramiko Library (cmd download command: PIP install - I https://pypi.doublan.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 input the target server's ip Or host name:\n$ ") 6 print("Please check whether server port 22 is open (unconfigured required configuration ssh service,Baidu)") 7 # TODO Tips 8 # Using command line module to give parameters 9 time.sleep(2) 10 username = input("$ enter one user name:\n$ ") 11 time.sleep(2) 12 password = input("$ Please enter the login password:\n$ ") 13 time.sleep(2) 14 action = input("$ Please select the action to be performed:g/p:\n$ ") 15 while (not (action == "g")) and (not (action == "p")): 16 action = input("$ Input error, please input again:g/p\n$ ") 17 time.sleep(2) 18 print("Your operation is:%s " % action) 19 # Default address if not entered 20 # Using command line module to give parameters 21 if action == "g": 22 remote_address = input("$ Enter the address of the file to be downloaded from the target server:\n$ ") 23 while remote_address is None: 24 remote_address = input("$ Please re-enter, can not be empty:\n$ ") 25 address = input("$ Enter the file storage address obtained(If it is empty, it will be the current directory address):\n$ ") 26 print("Operation in progress-- %s " % action) 27 ssh_server_get(ip_or_hostname, username, password, address, remote_address) 28 29 elif action == "p": 30 address = input("$ Enter the file address to upload:\n$ ") 31 while address is None: 32 address = input("$ Please re-enter, can not be empty:\n$ ") 33 remote_address = input("$ Enter the address where the target server stores the file(Blank is the default address\home\yourhostname):\n$ ") 34 print("Operation in progress-- %s " % action) 35 ssh_server_put(ip_or_hostname, username, password, address, remote_address) 36 37 time.sleep(2) 38 print("Operation complete")
This is the initialization work, because the port number of this software has been written 22, because it's the command line. I wanted to use the progress library to make dynamic animation, and I don't know how to use the asyncio process. The big guy who knows told 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("Unable to connect to the remote server, please check the 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()
Create a transport and then a 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
Then use pyinstaller and a download link with paramiko to change the library name. If you don't believe it, add the library name after - i
This is the pyinstaller command
-Package F as an exe
-w (not used here) do not pop up cmd
-i set application icon