He began to think about how to access the server file system as easily as xftp, so after some coding, he encapsulated the following QT components:
xFileBrowserLinux inherits from QWidget. Of course, this is just entertainment. My ultimate goal is to write something more convenient than xftp. First encapsulate the linux side components:
The main principle is to use the encapsulated pssh client library to connect to the Linux server (using the user name and password), and then maintain a long connection to execute the command to obtain the file directory information and refresh the display
The main functions are as follows:
Automatic reconnection function
After connecting to the Linux server, if the server hangs up or the sshd is out of service due to network reasons, it will be automatically reconnected until the reconnection succeeds and the information is obtained again. After disconnection, the status is displayed as a red dot and the connection is displayed as a green dot:
new file
Remote execution of touch
new directory
Execute mkdir -p remotely
ssh login
Call the local putty to bring in the server address, user name, password and port login. Even the password is automatically entered, pure and one click login. The effect is shown in the figure:
vnc login
Similar to ssh login, one click login to vnc uses the local vncviewer to call externally. Even the password is automatically entered, pure one click login
rename
Execute mv command remotely
delete
Execute rm -rf command remotely
The main code of xFileBrowserLinux is as follows (poorly written, serious personal style, light spray):
class xFileBrowserLinux : public QWidget { Q_OBJECT public: explicit xFileBrowserLinux(QWidget *parent = 0); pstring strhost; int iport; pstring strpwd; pstring struser; int iportvnc; pstring strpwdvnc; pstring getTypeNow();//Gets the current row type pstring getItemNow(pstring strcolname); pstring getPathFullNow();//Get the current full path (path plus file name) pstring getPathPwdNow();//Get current path QAction* pActionFirst;//The first menu is for adding after the outside QAction* newActionTop(QString name);//Add forward pssh *psh=NULL; ~xFileBrowserLinux(); //It needs to be initialized by itself and will be reconnected automatically void init(pstring host="82.156.128.240",int port=22,pstring pwd="123.asdf",pstring user="root",int iportvnc=2,pstring pwdvnc="sjcs_325"); void threadGetDataAndShow(); private: void ssh(); void vnc(); private slots: void slotSetConnectState(bool bState); void slotDoubleClick(int row,int col); void on_pbutUpLevel_clicked(); void on_pbutVNC_clicked(); void on_pbutSSH_clicked(); signals: void sigShowTable(plist<pliststring> lmdata, int keyid=0); void sigDoubleClick(int row,int col); void sigSetConnectState(bool bState); private: plist<pliststring> getNowFileAndDirs(); bool bstop=false; Ui::xFileBrowserLinux *ui; };
Of course, at present, this component can only look at information, and sftp transfer files and directories will be added later