全部博文(776)
分类: WINDOWS
2010-11-10 08:17:05
//FTP上传
bool MyFtp::up(const string& sourceFileName, const string& targetFileName)
{
int sts=0;
int fsz;
if (!connect())
return false;
FtpOptions(FTPLIB_CALLBACK, (long) NULL, conn);
struct REMFILE *f;
f = (struct REMFILE *) malloc(sizeof(struct REMFILE));
memset(f,0,sizeof(struct REMFILE));
f->fnm = strdup(sourceFileName.c_str());
fsz = TPub::getFileSize(f->fnm);
f->fsz = fsz;
fsz = fsz/100;
if (fsz)
{
FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn);
FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn);
FtpOptions(FTPLIB_CALLBACKARG, (long) f, conn);
FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz, conn);
}
sts = FtpPut(f->fnm,targetFileName.c_str(),'I',conn);
if (sts)
{
::PostMessage((HWND)(AfxGetApp()->GetMainWnd()->GetSafeHwnd()),WM_PROGRESS,100,NULL);
}
free(f->fnm);
free(f);
if (!sts)
{
_err = "ftp error: ";
_err = _err + FtpLastResponse(conn);
return false;
}
return true;
}