Unicode C
Unicode C
Remove a Remote FTP Directory (RMD)
See more FTP Examples
Demonstrates the Chilkat Ftp2.RemoveRemoteDir method, which removes a remote directory. The only argument is the remote directory path.
Background: Most FTP servers refuse to remove a directory that is not empty, so clearing a populated folder means deleting its contents first — or using
DeleteTree to clear the subtree and then removing the now-empty directory. After a removal, the cached indexed listing is not refreshed automatically; call ClearDirCache before relying on the old cache again.Chilkat Unicode C Downloads
#include <C_CkFtp2W.h>
void ChilkatSample(void)
{
BOOL success;
HCkFtp2W ftp;
success = FALSE;
// Demonstrates the Ftp2.RemoveRemoteDir method, which removes a remote directory. The only
// argument is the remote directory path.
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;
}
// FTP servers generally require the directory to be empty before it can be removed.
success = CkFtp2W_RemoveRemoteDir(ftp,L"uploads/old");
if (success == FALSE) {
wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
CkFtp2W_Dispose(ftp);
return;
}
wprintf(L"Directory removed.\n");
success = CkFtp2W_Disconnect(ftp);
if (success == FALSE) {
wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
CkFtp2W_Dispose(ftp);
return;
}
CkFtp2W_Dispose(ftp);
}