Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Setting Environment Variables for SCP TransfersDemonstrates how to set remote environment variables for an SCP transfer. Note 1: This example requires Chilkat v9.5.0.79 or greater. Note 2: Setting environment variables for SCP is only supported by some SSH servers.
#include <C_CkSshW.h> #include <C_CkScpW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkSshW ssh; BOOL success; HCkScpW scp; HCkJsonObjectW jsonEnvVars; const wchar_t *strEnvVars; const wchar_t *remotePath; const wchar_t *localPath; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. ssh = CkSshW_Create(); // First connect to an SSH server. success = CkSshW_Connect(ssh,L"example.com",22); if (success != TRUE) { wprintf(L"%s\n",CkSshW_lastErrorText(ssh)); CkSshW_Dispose(ssh); return; } // Wait a max of 5 seconds when reading responses.. CkSshW_putIdleTimeoutMs(ssh,5000); // Authenticate.. success = CkSshW_AuthenticatePw(ssh,L"myLogin",L"myPassword"); if (success != TRUE) { wprintf(L"%s\n",CkSshW_lastErrorText(ssh)); CkSshW_Dispose(ssh); return; } // After the SSH object is connected and authenticated, we use it // as the underlying transport in our SCP object. scp = CkScpW_Create(); success = CkScpW_UseSsh(scp,ssh); if (success != TRUE) { wprintf(L"%s\n",CkScpW_lastErrorText(scp)); CkSshW_Dispose(ssh); CkScpW_Dispose(scp); return; } // Specify the environment variables to be set in JSON as follows. // This example sets two environment variables. One is named "LCS_PASSWORD" and the other "MY_TEST_NAME". jsonEnvVars = CkJsonObjectW_Create(); CkJsonObjectW_putEmitCompact(jsonEnvVars,FALSE); CkJsonObjectW_UpdateString(jsonEnvVars,L"LCS_PASSWORD",L"secret"); CkJsonObjectW_UpdateString(jsonEnvVars,L"MY_TEST_NAME",L"abc"); strEnvVars = CkJsonObjectW_emit(jsonEnvVars); wprintf(L"%s\n",strEnvVars); // Setting the SendEnv property causes Chilkat to set each environment variable on the SSH server // prior to doing the upload or download. CkScpW_putSendEnv(scp,strEnvVars); // Do the upload.. remotePath = L"starfish.jpg"; localPath = L"qa_data/jpg/starfish.jpg"; success = CkScpW_UploadFile(scp,localPath,remotePath); if (success != TRUE) { wprintf(L"%s\n",CkScpW_lastErrorText(scp)); CkSshW_Dispose(ssh); CkScpW_Dispose(scp); CkJsonObjectW_Dispose(jsonEnvVars); return; } wprintf(L"SCP upload file success.\n"); // Disconnect CkSshW_Disconnect(ssh); CkSshW_Dispose(ssh); CkScpW_Dispose(scp); CkJsonObjectW_Dispose(jsonEnvVars); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.