BOOL FtpPutFile(Connection *Connect,LPCSTR loc,LPCSTR rem,BOOL Reput,int AsciiMode) { PROC(("FtpPutFile","[%s]->[%s] %s %s",loc,rem,Reput?"REGET":"NEW",AsciiMode?"ASCII":"BIN")); String Command, full_name; int ExitCode; int64_t Position; Assert(Connect && "FtpPutFile"); Connect->CacheReset(); if((AsciiMode && !Connect->ProcessCommand("ascii")) || (!AsciiMode && !Connect->ProcessCommand("bin"))) { Log(("!Set mode")); return FALSE; } if(AsciiMode) Reput = FALSE; //Remote file if(*rem=='\\' || (rem[0] && rem[1]==':'))//slash is really back, otherwise BUG rem = PointToName((char *)rem); if(Connect->Host.ServerType!=FTP_TYPE_MVS) { if(*rem != '/') { // full_name.printf("%s/%s", Connect->ToOEMDup(Connect->CurDir.c_str()), rem); full_name.printf("%s/%s", Connect->CurDir.c_str(), rem); rem = full_name.c_str(); } } if(Reput) { Position = FtpFileSize(Connect, rem); if(Position == -1) return FALSE; } else Position = 0; Connect->IOCallback = TRUE; //Append Connect->restart_point = Position; Command.printf("%s \x1%s\x1 \x1%s\x1", Position ? "appe" : "put", loc, rem); Log(("%s upload", Position ? "Try APPE" : "Use PUT")); ExitCode = Connect->ProcessCommand(Command); //Error APPE, try to resume using REST if(!ExitCode && Position && Connect->ResumeSupport) { Log(("APPE fail, try REST upload")); Connect->restart_point = Position; Command.printf("put \x1%s\x1 \x1%s\x1", loc, rem); ExitCode = Connect->ProcessCommand(Command); } Connect->IOCallback = FALSE; return ExitCode; }
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; } }