Esempio n. 1
0
BOOL FtpGetFile(Connection *Connect,LPCSTR lpszRemoteFile,LPCSTR lpszNewFile,BOOL Reget,int AsciiMode)
{
	PROC(("FtpGetFile","[%s]->[%s] %s %s",lpszRemoteFile,lpszNewFile,Reget?"REGET":"NEW",AsciiMode?"ASCII":"BIN"));
	String Command,
	       full_name;
	int  ExitCode;
	Assert(Connect && "FtpGetFile");

//mode
	if(AsciiMode && !Connect->ProcessCommand("ascii"))
	{
		Log(("!ascii ascii:%d",AsciiMode));
		return FALSE;
	}
	else if(!AsciiMode && !Connect->ProcessCommand("bin"))
	{
		Log(("!bin ascii:%d",AsciiMode));
		return FALSE;
	}

//Create directory
	Command = lpszNewFile;
	int m = Command.RChr('/');

	if(m != -1)
	{
		Command.SetLength(m);

		if(!DoCreateDirectory(Command.c_str()))
		{
			Log(("!CreateDirectory [%s]",Command.c_str()));
			return FALSE;
		}
	}

//Remote file
	if(Connect->Host.ServerType!=FTP_TYPE_MVS && *lpszRemoteFile != '/')
	{
		full_name = Connect->CurDir; //Connect->ToOEMDup(Connect->CurDir.c_str());
		AddEndSlash(full_name, '/');
		full_name.Add(lpszRemoteFile);
		lpszRemoteFile = full_name.c_str();
	}

//Get file
	Connect->IOCallback = TRUE;

	if(Reget && !Connect->ResumeSupport)
	{
		Connect->AddCmdLine(FMSG(MResumeRestart));
		Reget = FALSE;
	}

	Command.printf("%s \x1%s\x1 \x1%s\x1",
	               Reget ? "reget":"get",
	               lpszRemoteFile, lpszNewFile);
	ExitCode = Connect->ProcessCommand(Command);
	Connect->IOCallback = FALSE;
	return ExitCode;
}
Esempio n. 2
0
int
TclpCreateDirectory(
    CONST char *path)		/* Pathname of directory to create (UTF-8). */
{
    int result;
    Tcl_DString pathString;

    Tcl_WinUtfToTChar(path, -1, &pathString);
    result = DoCreateDirectory(&pathString);
    Tcl_DStringFree(&pathString);
    return result;
}
Esempio n. 3
0
static int 
TraversalCopy(
    Tcl_DString *srcPtr,	/* Source pathname to copy. */
    Tcl_DString *dstPtr,	/* Destination pathname of copy. */
    int type,			/* Reason for call - see TraverseWinTree() */
    Tcl_DString *errorPtr)	/* If non-NULL, initialized DString filled
				 * with UTF-8 name of file causing error. */
{
    TCHAR *nativeDst, *nativeSrc;
    DWORD attr;

    switch (type) {
	case DOTREE_F: {
	    if (DoCopyFile(srcPtr, dstPtr) == TCL_OK) {
		return TCL_OK;
	    }
	    break;
	}
	case DOTREE_PRED: {
	    if (DoCreateDirectory(dstPtr) == TCL_OK) {
		nativeSrc = (TCHAR *) Tcl_DStringValue(srcPtr);
		nativeDst = (TCHAR *) Tcl_DStringValue(dstPtr);
		attr = (*tclWinProcs->getFileAttributesProc)(nativeSrc);
		if ((*tclWinProcs->setFileAttributesProc)(nativeDst, attr) != FALSE) {
		    return TCL_OK;
		}
		TclWinConvertError(GetLastError());
	    }
	    break;
	}
        case DOTREE_POSTD: {
	    return TCL_OK;
	}
    }

    /*
     * There shouldn't be a problem with src, because we already
     * checked it to get here.
     */

    if (errorPtr != NULL) {
	nativeDst = (TCHAR *) Tcl_DStringValue(dstPtr);
	Tcl_WinTCharToUtf(nativeDst, -1, errorPtr);
    }
    return TCL_ERROR;
}
Esempio n. 4
0
void FTP::ExecuteQueueINT(QueueExecOptions* op)
{
	PROC(("ExecuteQueueINT","%d,%d",op->RestoreState,op->RemoveCompleted))
	FP_Screen       _scr;
	String          DefPath, LastPath, LastName;
	BOOL            rc;
	BOOL            needUpdate = FALSE;
	FTPUrl          *prev,*p,*tmp;
	FTPCopyInfo     ci;
	FAR_FIND_DATA   fd, ffd;
	//Copy info
	ci.asciiMode       = Host.AsciiMode;
	ci.ShowProcessList = FALSE;
	ci.AddToQueque     = FALSE;
	ci.MsgCode         = ocNone;
	ci.UploadLowCase   = Opt.UploadLowCase;
	//Check othe panel info
	PanelInfo pi;
	FP_Info->Control(INVALID_HANDLE_VALUE, FCTL_GETANOTHERPANELINFO, &pi);

	if(pi.PanelType != PTYPE_FILEPANEL ||
	        pi.Plugin)
		DefPath.Null();
	else
		DefPath = pi.CurDir;

	//DO full list
	prev        = NULL;
	p           = UrlsList;
	LastPath.Null();
	LastName.Null();

	while(p)
	{
//Check current host the same
		Log(("Queue: Check current host the same"));

		if(!hConnect ||
		        !Host.CmpConnected(&p->Host))
		{
			Host = p->Host;

			if(!FullConnect())
			{
				if(GetLastError() == ERROR_CANCELLED) break;

				p->Error.printf("%s: %s", FP_GetMsg(MQCanNotConnect), __WINError());
				goto Skip;
			}

			ResetCache=TRUE;
		}

//Apply other parameters
		Log(("Queue: Apply other parameters"));
		Host = p->Host;
		hConnect->InitData(&Host,-1);
		hConnect->InitIOBuff();
//Change local dir
		Log(("Queue: Change local dir"));

		do
		{
			char *m = p->Download ? p->DestPath.c_str() : p->SrcPath.c_str();

			if(!m[0]) m = DefPath.c_str();

			if(!m[0])
			{
				p->Error = FP_GetMsg(MQNotLocal);
				goto Skip;
			}

			if(SetCurrentDirectory(m)) break;

			if(DoCreateDirectory(m))
				if(SetCurrentDirectory(m)) break;

			p->Error.printf(FP_GetMsg(MQCanNotChangeLocal), m, __WINError());
			goto Skip;
		}
		while(0);

//Check local file
		Log(("Queue: Check local file"));

		if(!p->Download)
		{
			if(!FRealFile(p->FileName.cFileName, &fd))
			{
				p->Error.printf(FP_GetMsg(MQNotFoundSource), p->FileName.cFileName, __WINError());
				goto Skip;
			}
		}

//IO file
		Log(("Queue: IO file"));
		//Last used FTP path and name
		LastPath = p->Download ? p->SrcPath : p->DestPath;
		LastName = PointToName(p->FileName.cFileName);

		//DOWNLOAD ------------------------------------------------
		if(p->Download)
		{
			ci.Download  = TRUE;
			ci.SrcPath = p->SrcPath;
			AddEndSlash(ci.SrcPath, '/');
			ci.SrcPath.cat(p->FileName.cFileName);

			if(p->DestPath.Length())
			{
				FixFileNameChars(p->DestPath);
				ci.DestPath = p->DestPath;
			}
			else
				ci.DestPath = DefPath;

			AddEndSlash(ci.DestPath, '\\');
			ci.DestPath.cat(FixFileNameChars(p->FileName.cFileName,TRUE));
			__int64 fsz = FtpFileSize(hConnect, ci.SrcPath.c_str());
			hConnect->TrafficInfo->Init(hConnect, MStatusDownload, 0, NULL);
			hConnect->TrafficInfo->InitFile(fsz, ci.SrcPath.c_str(), ci.DestPath.c_str());

			if(FRealFile(ci.DestPath.c_str(),&fd))
			{
				if(fsz != -1)
				{
					ffd = fd;
					ffd.nFileSizeHigh = (DWORD)((fsz >> 32) & MAX_DWORD);
					ffd.nFileSizeLow  = (DWORD)(fsz & MAX_DWORD);
					ci.MsgCode  = AskOverwrite(MDownloadTitle, TRUE, &fd, &ffd, ci.MsgCode, FALSE);
				}
				else
					ci.MsgCode  = AskOverwrite(MDownloadTitle, TRUE, &fd, NULL, ci.MsgCode, FALSE);

				switch(ci.MsgCode)
				{
					case   ocOverAll:
					case      ocOver:
						break;
					case      ocSkip:
					case   ocSkipAll:
						goto Skip;
					case    ocResume:
					case ocResumeAll:
						break;
					case     ocNewer:
					case  ocNewerAll:
						goto Skip;
				}

				if(ci.MsgCode == ocCancel)
				{
					SetLastError(ERROR_CANCELLED);
					break;
				}
			}