From 3d696f561ea7377a49c4f95c73e9fccc081eaa6e Mon Sep 17 00:00:00 2001 From: cyd01 Date: Thu, 30 Apr 2020 19:29:11 +0200 Subject: [PATCH] feat: new settings Dynamic WinSCP protocol for WinSCP intgration [#161] --- 0.73_My_PuTTY/config.c | 28 ++++++++++++++++++++-------- 0.73_My_PuTTY/putty.h | 1 + 0.73_My_PuTTY/settings.c | 2 ++ kitty.c | 32 ++++++++++++++++++++------------ kitty_ini.txt | 11 +++-------- kitty_registry.c | 1 + kitty_savedump.c | 2 ++ kitty_settings.c | 2 ++ 8 files changed, 51 insertions(+), 28 deletions(-) diff --git a/0.73_My_PuTTY/config.c b/0.73_My_PuTTY/config.c index d30d284..d8e56dd 100644 --- a/0.73_My_PuTTY/config.c +++ b/0.73_My_PuTTY/config.c @@ -3524,12 +3524,28 @@ if( !GetPuttyFlag() ) { } #ifdef MOD_PERSO - if (!midsession) { - s = ctrl_getset(b, "Connection/SSH", "pscp", "PSCP integration") ; - ctrl_checkbox(s, "Send file in current directory", NO_SHORTCUT, + if( !midsession && !GetPuttyFlag() ) { + s = ctrl_getset(b, "Connection/SSH", "pscp", "WinSCP and PSCP integration") ; + ctrl_checkbox(s, "Send file in current directory (pscp only)", NO_SHORTCUT, HELPCTX(no_help), conf_checkbox_handler, - I(CONF_scp_auto_pwd)); + I(CONF_scp_auto_pwd)); + ctrl_radiobuttons(s, "WinSCP protocol:", NO_SHORTCUT, 7, + HELPCTX(no_help), + conf_radiobutton_handler, + I(CONF_winscpprot), + "scp", NO_SHORTCUT, I(0), + "sftp", NO_SHORTCUT, I(1), + "ftp", NO_SHORTCUT, I(2), + "ftps", NO_SHORTCUT, I(3), + "ftpes", NO_SHORTCUT, I(4), + "http", NO_SHORTCUT, I(5), + "https", NO_SHORTCUT, I(6), + NULL); + ctrl_editbox(s, "SFTP connect", NO_SHORTCUT, 100, + HELPCTX(no_help), + conf_editbox_handler, I(CONF_sftpconnect), + I(1)); } #endif @@ -4081,10 +4097,6 @@ if( !GetPuttyFlag() ) { HELPCTX(no_help), conf_editbox_handler, I(CONF_comment), I(1)); - ctrl_editbox(s, "SFTP connect", NO_SHORTCUT, 100, - HELPCTX(no_help), - conf_editbox_handler, I(CONF_sftpconnect), - I(1)); } #endif } diff --git a/0.73_My_PuTTY/putty.h b/0.73_My_PuTTY/putty.h index cf18dc4..29f3654 100644 --- a/0.73_My_PuTTY/putty.h +++ b/0.73_My_PuTTY/putty.h @@ -1555,6 +1555,7 @@ NORETURN void cleanup_exit(int); X(BOOL, NONE, saveonexit) \ X(INT, NONE, icone) \ X(FILENAME, NONE, iconefile) \ + X(INT, NONE, winscpprot) \ X(STR, NONE, sftpconnect) \ X(STR, NONE, folder) \ X(STR, NONE, password) \ diff --git a/0.73_My_PuTTY/settings.c b/0.73_My_PuTTY/settings.c index afb0582..bf1a8e5 100644 --- a/0.73_My_PuTTY/settings.c +++ b/0.73_My_PuTTY/settings.c @@ -884,6 +884,7 @@ void save_open_settings(settings_w *sesskey, Conf *conf) write_setting_b(sesskey, "SaveOnExit", conf_get_bool(conf, CONF_saveonexit) ); write_setting_i(sesskey, "Icone", conf_get_int(conf, CONF_icone) ); write_setting_filename(sesskey, "IconeFile", conf_get_filename(conf, CONF_iconefile) ); + write_setting_i(sesskey, "WinSCPProtocol", conf_get_int(conf, CONF_winscpprot) ); write_setting_s(sesskey, "SFTPConnect", conf_get_str(conf, CONF_sftpconnect) ); Filename * fn = filename_from_str( "" ) ; conf_set_filename(conf,CONF_scriptfile,fn); @@ -1518,6 +1519,7 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gppb(sesskey, "SaveOnExit", false, conf, CONF_saveonexit ); gppi(sesskey, "Icone", 1, conf, CONF_icone ); gppfile(sesskey, "IconeFile", conf, CONF_iconefile ); + gppi(sesskey, "WinSCPProtocol", 1, conf, CONF_winscpprot ); gpps(sesskey, "SFTPConnect", "", conf, CONF_sftpconnect ); gppfile(sesskey, "Scriptfile", conf, CONF_scriptfile ); Filename * fn = filename_from_str( "" ) ; diff --git a/kitty.c b/kitty.c index 9302a78..d7bd710 100644 --- a/kitty.c +++ b/kitty.c @@ -350,7 +350,7 @@ char * WinSCPPath = NULL ; char * PSCPPath = NULL ; // Options pour le programme pscp.exe -char PSCPOptions[1024] = "-scp -r" ; +char PSCPOptions[1024] = "-r" ; // Chemin vers le programme plink.exe char * PlinkPath = NULL ; @@ -1303,7 +1303,7 @@ void CreateDefaultIniFile_old( void ) { writeINI( KittyIniFile, INIT_SECTION, "paste", "no" ) ; writeINI( KittyIniFile, INIT_SECTION, "#PlinkPath", "" ) ; writeINI( KittyIniFile, INIT_SECTION, "#PSCPPath", "" ) ; - writeINI( KittyIniFile, INIT_SECTION, "#PSCPOptions", "-scp -r" ) ; + writeINI( KittyIniFile, INIT_SECTION, "#PSCPOptions", "-r" ) ; writeINI( KittyIniFile, INIT_SECTION, "#remotedir", "" ) ; #ifdef MOD_PORTABLE writeINI( KittyIniFile, INIT_SECTION, "savemode", "dir" ) ; @@ -1330,7 +1330,6 @@ void CreateDefaultIniFile_old( void ) { writeINI( KittyIniFile, INIT_SECTION, "#uploaddir", "." ) ; writeINI( KittyIniFile, INIT_SECTION, "#userpasssshnosave", "no" ) ; writeINI( KittyIniFile, INIT_SECTION, "#WinSCPPath", "" ) ; - writeINI( KittyIniFile, INIT_SECTION, "#WinSCPProtocol", "sftp" ) ; #ifdef MOD_ZMODEM writeINI( KittyIniFile, INIT_SECTION, "zmodem", "yes" ) ; #endif @@ -2049,7 +2048,8 @@ void SendOneFile( HWND hwnd, char * directory, char * filename, char * distantdi if( strlen(PSCPOptions)>0 ) { strcat( buffer, PSCPOptions ) ; strcat( buffer, " " ) ; } - //strcat( buffer, "-scp -r " ) ; //strcat( buffer, "-batch " ) ; + if( conf_get_int(conf, CONF_winscpprot)==0 ) { strcat( buffer, "-scp " ) ; } + else { strcat( buffer, "-sftp " ) ; } //if( GetAutoStoreSSHKeyFlag() ) strcat( buffer, "-auto-store-sshkey " ) ; @@ -2266,7 +2266,8 @@ void GetOneFile( HWND hwnd, char * directory, const char * filename ) { if( strlen(PSCPOptions)>0 ) { strcat( buffer, PSCPOptions ) ; strcat( buffer, " " ) ; } - //strcat( buffer, "-scp -r " ) ; + if( conf_get_int(conf, CONF_winscpprot)==0 ) { strcat( buffer, "-scp " ) ; } + else { strcat( buffer, "-sftp " ) ; } //if( GetAutoStoreSSHKeyFlag() ) strcat( buffer, "-auto-store-sshkey " ) ; @@ -2381,9 +2382,11 @@ void GetFile( HWND hwnd ) { if( strlen(PSCPOptions)>0 ) { strcat( buffer, PSCPOptions ) ; strcat( buffer, " " ) ; } + if( conf_get_int(conf, CONF_winscpprot)==0 ) { strcat( buffer, "-scp " ) ; } + else { strcat( buffer, "-sftp " ) ; } if( conf_get_int(conf,CONF_sshprot) == 3 ) { // SSH-2 Only (voir putty.h) strcat( buffer, "-2 " ) ; - } + } if( ReadParameter( INIT_SECTION, "pscpport", pscpport ) ) { pscpport[17]='\0'; @@ -3867,12 +3870,17 @@ void StartWinSCP( HWND hwnd, char * directory, char * host, char * user ) { if( !GetShortPathName( WinSCPPath, shortpath, 4095 ) ) return ; + switch( conf_get_int(conf, CONF_winscpprot) ) { + case 0: strcpy( proto, "scp" ) ; break ; + case 2: strcpy( proto, "ftp" ) ; break ; + case 3: strcpy( proto, "ftps" ) ; break ; + case 4: strcpy( proto, "ftpes" ) ; break ; + case 5: strcpy( proto, "http" ) ; break ; + case 6: strcpy( proto, "https" ) ; break ; + default: strcpy( proto, "sftp" ) ; + } + if( conf_get_int(conf,CONF_protocol) == PROT_SSH ) { - strcpy( proto, "sftp" ) ; - if( ReadParameter( INIT_SECTION, "WinSCPProtocol", buffer ) ) { - if( (!strcmp( buffer, "scp" )) || (!strcmp( buffer, "sftp" )) || (!strcmp( buffer, "ftp" )) ) - strcpy( proto, buffer) ; - } sprintf( cmd, "%s %s://", shortpath, proto ) ; if( strlen( conf_get_str(conf, CONF_sftpconnect) ) > 0 ) { @@ -3911,7 +3919,7 @@ void StartWinSCP( HWND hwnd, char * directory, char * host, char * user ) { } } } else { - sprintf( cmd, "%s ftp://%s", shortpath, conf_get_str(conf,CONF_username) ) ; + sprintf( cmd, "%s %s://%s", shortpath, proto, conf_get_str(conf,CONF_username) ) ; if( strlen( conf_get_str(conf,CONF_password) ) > 0 ) { char bufpass[1024] ; strcat( cmd, ":" ); diff --git a/kitty_ini.txt b/kitty_ini.txt index 1f9d9c0..703eb2b 100644 --- a/kitty_ini.txt +++ b/kitty_ini.txt @@ -129,8 +129,8 @@ paste=no ;PSCPPath= ; PSCPOptions: the additionnal options to pass to the pscp command (for download or upload file) -; default settings are -scp -r (force scp mode, and recursive mode) -;PSCPOptions=-scp -r +; default settings are -r (force recursive mode) +;PSCPOptions=-r ; ReconnectDelay: the delay before trying to reconnect automatically (in seconds) ReconnectDelay=5 @@ -183,14 +183,9 @@ userpasssshnosave=no ; winrol: enable/disable the rolling feature (rolling into the title bar) winrol=yes -; WinSCPPath: the full path to the winscp.exe binary +; WinSCPPath: the full path to the winscp.exe binary: ;WinSCPPath= -; WinSCPProtocol: force the protocol for WinSCP integration -; Allowed values are: scp, sftp, ftp -; Default value is: sftp -;WinSCPProtocol=sftp - ; wintitle: enable/disable the enhanced title feature (for protected mode and window size) wintitle=yes diff --git a/kitty_registry.c b/kitty_registry.c index 1ad8170..454e21e 100644 --- a/kitty_registry.c +++ b/kitty_registry.c @@ -478,6 +478,7 @@ return 1 ; RegDeleteValue( hSubKey, "Folder" ) ; RegDeleteValue( hSubKey, "Icone" ) ; RegDeleteValue( hSubKey, "IconeFile" ) ; + RegDeleteValue( hSubKey, "WinSCPProtocol" ) ; RegDeleteValue( hSubKey, "SFTPConnect" ) ; RegDeleteValue( hSubKey, "InitDelay" ) ; RegDeleteValue( hSubKey, "Password" ) ; diff --git a/kitty_savedump.c b/kitty_savedump.c index 64d1716..f37e540 100644 --- a/kitty_savedump.c +++ b/kitty_savedump.c @@ -490,6 +490,7 @@ void SaveDumpConfig( FILE *fp, Conf * conf ) { fprintf( fp, "saveonexit=%d\n", conf_get_bool(conf,CONF_saveonexit) ) ; fprintf( fp, "icone=%d\n", conf_get_int(conf,CONF_icone) ) ; fprintf( fp, "iconefile=%s\n", conf_get_filename(conf,CONF_iconefile)->path ) ; + fprintf( fp, "winscpprot=%d\n", conf_get_int(conf,CONF_winscpprot) ) ; fprintf( fp, "sftpconnect=%s\n", conf_get_str(conf,CONF_sftpconnect) ) ; fprintf( fp, "folder=%s\n", conf_get_str(conf,CONF_folder) ) ; /* On decrypte le password */ @@ -627,6 +628,7 @@ void SaveDumpConfig( FILE *fp, Conf * conf ) { fprintf( fp, "WinHeight=%d\nWinrolFlag=%d\nAutoSendToTray=%d\nNoKittyFileFlag=%d\nConfigBoxHeight=%d\nConfigBoxWindowHeight=%d\nConfigBoxNoExitFlag=%d\nUserPassSSHNoSave=%d\nPuttyFlag=%d\n",WinHeight,WinrolFlag,AutoSendToTray,NoKittyFileFlag,ConfigBoxHeight,ConfigBoxWindowHeight,ConfigBoxNoExitFlag,GetUserPassSSHNoSave(),PuttyFlag); fprintf( fp,"BackgroundImageFlag=%d\n",GetBackgroundImageFlag() ); + fprintf( fp,"PSCPOptions=%s\n",PSCPOptions ); #ifdef MOD_RECONNECT fprintf( fp,"AutoreconnectFlag=%d\nReconnectDelay=%d\n",AutoreconnectFlag,ReconnectDelay ); #endif diff --git a/kitty_settings.c b/kitty_settings.c index 6c3d63f..0999704 100644 --- a/kitty_settings.c +++ b/kitty_settings.c @@ -391,6 +391,7 @@ void save_open_settings_forced(char *filename, Conf *conf) { write_setting_b_forced(sesskey, "SaveOnExit", conf_get_bool(conf, CONF_saveonexit) ); write_setting_i_forced(sesskey, "Icone", conf_get_int(conf, CONF_icone) ); write_setting_filename_forced(sesskey, "IconeFile", conf_get_filename(conf, CONF_iconefile) ); + write_setting_i_forced(sesskey, "WinSCPProtocol", conf_get_int(conf, CONF_winscpprot) ); write_setting_s_forced(sesskey, "SFTPConnect", conf_get_str(conf, CONF_sftpconnect) ); Filename * fn = filename_from_str( "" ) ; conf_set_filename(conf,CONF_scriptfile,fn); @@ -1016,6 +1017,7 @@ void load_open_settings_forced(char *filename, Conf *conf) { gppb_forced(sesskey, "SaveOnExit", false, conf, CONF_saveonexit ); gppi_forced(sesskey, "Icone", 1, conf, CONF_icone ); gppfile_forced(sesskey, "IconeFile", conf, CONF_iconefile ); + gppi_forced(sesskey, "WinSCPProtocol", 1, conf, CONF_winscpprot ); gpps_forced(sesskey, "SFTPConnect", "", conf, CONF_sftpconnect ); gppfile_forced(sesskey, "Scriptfile", conf, CONF_scriptfile ); Filename * fn = filename_from_str( "" ) ;