Unicode C
Unicode C
Create an FTP Upload Plan
See more FTP Examples
Demonstrates the Chilkat Ftp2.CreatePlan method, which creates and returns a textual upload plan for a local directory. The only argument is the local directory. The object must be connected, because the plan records the current absolute remote directory together with the local source paths.
Note: The local paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: A plan is a saved, resumable description of an upload — the list of local files and their absolute remote destinations — computed once and executed later (or on another run) with
PutPlan. Separating planning from execution suits large or unreliable transfers: the plan can be reviewed, stored, and re-run, and because it records absolute remote paths it stays correct even if the working directory later changes.Chilkat Unicode C Downloads
#include <C_CkFtp2W.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
BOOL success;
HCkFtp2W ftp;
const wchar_t *plan;
HCkStringBuilderW sbPlan;
success = FALSE;
// Demonstrates the Ftp2.CreatePlan method, which creates and returns a textual upload plan for a
// local directory. The only argument is the local directory. The object must be connected,
// because the plan records the current absolute remote directory.
ftp = CkFtp2W_Create();
CkFtp2W_putHostname(ftp,L"ftp.example.com");
CkFtp2W_putUsername(ftp,L"myFtpLogin");
// Normally you would not hard-code the password in source. You should instead obtain it
// from an interactive prompt, environment variable, or a secrets vault.
CkFtp2W_putPassword(ftp,L"myPassword");
success = CkFtp2W_Connect(ftp);
if (success == FALSE) {
wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
CkFtp2W_Dispose(ftp);
return;
}
success = CkFtp2W_ChangeRemoteDir(ftp,L"public_html");
if (success == FALSE) {
wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
CkFtp2W_Dispose(ftp);
return;
}
// The plan captures which local files to upload and the absolute remote destination. Save it so
// the upload can be run (or resumed) later with PutPlan.
plan = CkFtp2W_createPlan(ftp,L"qa_data/site");
if (CkFtp2W_getLastMethodSuccess(ftp) == FALSE) {
wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
CkFtp2W_Dispose(ftp);
return;
}
// Persist the plan text for later use.
sbPlan = CkStringBuilderW_Create();
CkStringBuilderW_Append(sbPlan,plan);
success = CkStringBuilderW_WriteFile(sbPlan,L"qa_output/upload_plan.txt");
if (success == FALSE) {
wprintf(L"%s\n",CkStringBuilderW_lastErrorText(sbPlan));
CkFtp2W_Dispose(ftp);
CkStringBuilderW_Dispose(sbPlan);
return;
}
wprintf(L"Upload plan created.\n");
success = CkFtp2W_Disconnect(ftp);
if (success == FALSE) {
wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
CkFtp2W_Dispose(ftp);
CkStringBuilderW_Dispose(sbPlan);
return;
}
CkFtp2W_Dispose(ftp);
CkStringBuilderW_Dispose(sbPlan);
}