Renaming Files and Directories on an FTP Server
A version of this page is also available for
4/8/2010
Files and directories on an FTP server can be renamed using the FtpRenameFile function. FtpRenameFile accepts two NULL-terminated strings that contain either partially or fully qualified names relative to the current directory. The function changes the name of the file designated by the first string to the name designated by the second string.
The following example shows how to rename the file or directory indicated by the IDC_FTPEdit2 edit box. The HINTERNET handle hSecondary was created by InternetConnect after establishing an FTP session. DisplayDir is another function that is designed to enumerate the directory.
int WINAPI RenameFile(HWND hX)
{
char strInFile[80];
char strOutFile[80];
strInFile[0]=0;
strOutFile[0]=0;
GetDlgItemText(hX,IDC_FTPEdit3,strOutFile,80);
GetDlgItemText(hX,IDC_FTPEdit2,strInFile,80);
if ((strlen(strOutFile)==0) || (strlen(strInFile)==0))
{
MessageBox(hX,"Target File or Destination File Missing","Put File",MB_OK);
return 0;
}
else
{
if(!FtpRenameFile(hSecondary,strInFile,strOutFile))
{
ErrorOut(hX,GetLastError(),"Get File");
DisplayDir(hX,INTERNET_FLAG_RELOAD);
return 0;
}
else
{
return DisplayDir(hX,INTERNET_FLAG_RELOAD);
}
}
}//end