Beispiel #1
0
BOOL FtpGetFtpDirectory(Connection *Connect)
{
	String         s, s1;
	FTPDirList     dl;
	char          *m;
	FTPServerInfo  si;
	WORD           idx;
	//Exec
	{
		FP_Screen  _scr;

		if(!Connect->ProcessCommand("pwd"))
			return FALSE;
	}
	Connect->GetReply(s);

	do
	{
		//Detect if unknown
		si.ServerType = Connect->Host.ServerType;
		StrCpy(si.ServerInfo, Connect->SystemInfo, ARRAYSIZE(si.ServerInfo));
		idx = Connect->Host.ServerType;

		if(idx == FTP_TYPE_DETECT || idx == FTP_TYPE_INVALID)
			idx = dl.DetectDirStringType(&si, s.c_str());

		//Parse
		FTPType*   tp;
		char       tmp[ 1024 ];  //There is not way to use String.

		if((tp=dl.GetType(idx)) != NULL &&
		        tp->PWDParse &&
		        tp->PWDParse(&si, s.c_str(), tmp, sizeof(tmp)))
		{
			Connect->CurDir = tmp;
			break;
		}

		//Del digits
		m = s.c_str();

		while(*m && (isdigit(*m) || strchr("\t\b ",*m) != NULL)) m++;

		if(!m[0])
			return FALSE;

		s.Del(0, (int)(m-s.c_str()));

		//Decode FF
		if(Connect->Host.UndupFF)
		{
			for(m = s.c_str(); *m; m++)
			{
				if(m[0] == (char)0xFF && m[1] == (char)0xFF)
				{
					s1.Add((char)0xFF);
					m++;
				}
				else
					s1.Add(*m);
			}

			s = s1;
		}

		//Set classic path
		/* Unix:
		     - name enclosed with '"'
		     - if '"' is in name it doubles
		*/
		int b;

		if((b=s.Chr('\"')) != -1)
		{
			s1.Null();

			for(int n = b+1; n < s.Length(); n++)
				if(s[n] == '\"')
				{
					if(s[n+1] == '\"')
					{
						s1.Add(s[n]);
						n++;
					}
					else
						break;
				}
				else
					s1.Add(s[n]);

			Connect->CurDir = s1;
		}
		else
			//Raw
			Connect->CurDir = s;
	}
	while(0);

	//Remove NL\CR
	int num;

	while((num=Connect->CurDir.Chr("\r\n")) != -1)
		Connect->CurDir.SetLength(num);

	return TRUE;
}