Example #1
0
int CzHttp::RenameFtpFile( char *name, char *newname )
{
    // FTPファイルをリネーム
    //
    int i;
    if ( mode != CZHTTP_MODE_FTPREADY ) {
        return -1;
    }
    if ( newname == NULL ) {
        i = FtpDeleteFile( hService, name );
    } else {
        i = FtpRenameFile( hService, name, newname );
    }
    if ( i == 0 ) return -1;
    GetFtpResponse();
    return 0;
}
Example #2
0
File: net.cpp Project: begoon/stuff
/*
  Name: fdel()

  Description: deletes file from ftp.

  Example: fdel("ftp://*****:*****@ftp.server.org/dir/file.ext");

  Parameters:
         [in] void *param - see example.

  Return value:
          ON SUCCESS - '1'.
          ON   ERROR - '0'.

  Revision: 16.01.2007
*/
unsigned long __stdcall net::fdel(void *param)
{
  char *par = (char *)param;

  InterlockedExchange((long *)&net::last_err, (long)net::WAIT);

  if(par == NULL)
  {
    InterlockedExchange((long *)&net::last_err, (long)net::ERR);
    return 0;
  }

  if(*(char *)par == 0)
  {
    InterlockedExchange((long *)&net::last_err, (long)net::ERR);
    return 0;
  }
  
  char root_dir[] = "/";

  // user
  char *user = strstr(par, "ftp://");
  if(NULL == user)
  {
    user = par;
  }
  else
  {
    user = par + lstrlen("ftp://");
  }

  // pass
  char *pass = user;
  while((*pass != 0x00) && (*pass != ':')) pass++;
  if(*pass == ':') // delimiter ':' found
  {
    *pass = 0x00;
    pass++;
  }
  else
  {
    InterlockedExchange((long *)&net::last_err, (long)net::ERR);
    if(par != NULL) delete[]par;
    return 0;
  }

  // host
  char *host = pass;
  while((*host != 0x00) && (*host != '@')) host++;
  if(*host == '@') // delimiter ':' found
  {
    *host = 0x00;
    host++;
  }
  else
  {
    InterlockedExchange((long *)&net::last_err, (long)net::ERR);
    if(par != NULL) delete[]par;
    return 0;
  }

  // dir
  char *dir = host;
  while((*dir != 0x00) && (*dir != '/')) dir++;
  if(*dir == '/')
  {
    *dir = 0x00;
    dir++;
  }
  else
  {
    InterlockedExchange((long *)&net::last_err, (long)net::ERR);
    if(par != NULL) delete[]par;
    return 0;
  }

  // file
  char *remote_file = dir;
  // forward to end
  while(*remote_file != 0x00) remote_file++;
  // back to last '/'
  while((remote_file != dir) && (*remote_file != '/')) remote_file--;
  if(*remote_file == '/')
  {
    *remote_file = 0x00;
    remote_file++;
  }
  else // remote file in root dir
  {
    dir = root_dir;
  }
  
  HINTERNET hInternet = ::InternetOpen(HTTP_USER_AGENT, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  if(hInternet == NULL)
  {
    ::InternetCloseHandle(hInternet);
    InterlockedExchange((long *)&net::last_err, (long)net::ERR);
    if(par != NULL) delete[]par;
    return 0;
  }

    HINTERNET hConnect = ::InternetConnect(hInternet, host, INTERNET_INVALID_PORT_NUMBER, user, pass, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
  if(hConnect == NULL)
  {
    ::InternetCloseHandle(hConnect);
    ::InternetCloseHandle(hInternet);
    InterlockedExchange((long *)&net::last_err, (long)net::ERR);
    if(par != NULL) delete[]par;
    return 0;
  }

  if(!FtpSetCurrentDirectory(hConnect, dir))
  {
    ::InternetCloseHandle(hConnect);
    ::InternetCloseHandle(hInternet);
    InterlockedExchange((long *)&net::last_err, (long)net::ERR);
    if(par != NULL) delete[]par;
    return 0;
  }

  if(!FtpDeleteFile(hConnect, remote_file))
  {
    ::InternetCloseHandle(hConnect);
    ::InternetCloseHandle(hInternet);
    InterlockedExchange((long *)&net::last_err, (long)net::ERR);
    if(par != NULL) delete[]par;
    return 0;
  }

  ::InternetCloseHandle(hConnect);
  ::InternetCloseHandle(hInternet);
  InterlockedExchange((long *)&net::last_err, (long)net::OK);
  if(par != NULL) delete[]par;

  return 1;
}
Example #3
0
BOOL idDeleteCB(PluginPanelItem* p,LPVOID dt)
{
	PROC(("idDeleteCB", "%p,%p [%s]", p, dt, FTP_FILENAME(p)));
	int      rres;
	FTPHost* h       = FTPHost::Convert(p);
	char    *CurName = FTP_FILENAME(p);
	char    *m;

	if(((DeleteData*)dt)->ShowHosts && !h)
		return TRUE;

//Ask
	if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
	{
		if(!((DeleteData*)dt)->DeleteAllFolders &&
		        IS_SILENT(((DeleteData*)dt)->OpMode))
		{
			LPCSTR MsgItems[]=
			{
				((DeleteData*)dt)->ShowHosts ? FP_GetMsg(MDeleteHostsTitle):FP_GetMsg(MDeleteTitle),
				((DeleteData*)dt)->ShowHosts ? FP_GetMsg(MDeleteHostFolder):FP_GetMsg(MDeleteFolder),
				CurName,
				FP_GetMsg(MDeleteGroupDelete), FP_GetMsg(MDeleteGroupAll), FP_GetMsg(MDeleteGroupCancel)
			};
			rres = FMessage(FMSG_WARNING|FMSG_DOWN, NULL,
			                MsgItems, ARRAYSIZE(MsgItems),
			                3);

			switch(rres)
			{
					/*ESC*/
				case -1:
					return FALSE;
					/*Del*/
				case  0:
					break;
					/*DelAll*/
				case  1:
					((DeleteData*)dt)->DeleteAllFolders = TRUE;
					break;
					/*Cancel*/
				case  2:
					return FALSE;
			}
		}
	}

//Display
	SaveConsoleTitle::Text(CurName);
	FtpConnectMessage(((DeleteData*)dt)->hConnect, MDeleteTitle, PointToName(CurName));

//===============================
//Hosts
	if(((DeleteData*)dt)->ShowHosts)
		return FP_DeleteRegKeyAll(h->RegKey);

//===============================
//FTP
	m = strrchr(CurName,'/');

	if(m) CurName = m+1;

	if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
	{
//FTP directory
		//Succ delete
		if(FtpRemoveDirectory(((DeleteData*)dt)->hConnect, CurName))
		{
			if(Opt.UpdateDescriptions) p->Flags |= PPIF_PROCESSDESCR;

			return TRUE;
		}
	}
	else
	{
//FTP file
		//Succ delete
		if(FtpDeleteFile(((DeleteData*)dt)->hConnect,CurName))
		{
			if(Opt.UpdateDescriptions) p->Flags |= PPIF_PROCESSDESCR;

			return TRUE;
		}
	}

//Error
	Log(("Del error: %s", ((DeleteData*)dt)->SkipAll ? "SkipAll" : "Ask"));

	if(((DeleteData*)dt)->SkipAll == FALSE)
	{
		rres = FtpConnectMessage(((DeleteData*)dt)->hConnect, MCannotDelete, CurName, -MCopySkip, MCopySkipAll);

		switch(rres)
		{
			/*skip*/     case 0:
				Log(("Skip"));
				return TRUE;
				/*skip all*/
			case 1:
				((DeleteData*)dt)->SkipAll = TRUE;
				Log(("SkipAll"));
				return TRUE;
			default:
				Log(("Other"));
				SetLastError(ERROR_CANCELLED);
				return FALSE;
		}
	}
	else
		return TRUE;
}