How can I use OpenFile function in CFtpConnection class???

Hi !

  I want to open a file in the server and append to it .I used OpenFile fn for CFtpConnection object and successfully wrote to it.But I want to append to it ?I read seek fn doesn't work for CFtp objects?How can i do that then ???

   pls help?

Thanks,
ceena.
ceenaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

waseemanisCommented:
There doesn't seem to be any inbuilt stuff for that , but you can copy the file locally, and then append to it, and put it back on the server. This obviously, the longer way out....but for now, seems to be the only one !!

Luck,
Waseem.
0
AndersonAdrianCommented:
Here's code that will download a file from an FTP site, it should get you started.  Once you have the file, make the changes, then to upload, you do follow the same steps as downloading except call CFtpConnection::PutFile(LPCTSTR pstrLocalFile, LPCTSTR pstrRemoteFile, DWORD dwFlags = FTP_TRANSFER_TYPE_BINARY, DWORD dwContext = 1 );

--Good Luck


CInternetSession session;
CFtpConnection* pServer = NULL;
CInternetFile* pFile = NULL;

char sFile[] = "ftp://ftp.foobar.com/pub/file.exe";
char* sPath;

try
{
// check to see if the URL is reasonable

CString strServerName;
CString strObject;
CString strDir;
CString strFile;
int nPos;
INTERNET_PORT nPort;
DWORD dwServiceType;

if (!AfxParseURL(sFile, dwServiceType, strServerName, strObject, nPort) ||
dwServiceType != INTERNET_SERVICE_FTP)
{
ASSERT(0); //bad URL
return NULL;
}

pServer = session.GetFtpConnection(strServerName, NAME, PASSWORD, nPort);

nPos = strObject.ReverseFind('/');
strDir = strObject.Left(nPos);
strFile = strObject.Right(strObject.GetLength() - nPos -1);

strDir.Delete(0);

pServer->SetCurrentDirectory(strDir);
CFtpFileFind ftpFileFind(pServer);

if(ftpFileFind.FindFile(strFile))
{
pFile = pServer->OpenFile(strFile);
}


CFile file;
char* sTmp;

sTmp = (char*)malloc(_MAX_PATH);
sPath = (char*)malloc(_MAX_PATH);

GetTempPath( _MAX_PATH, sTmp);

GetTempFileName(sTmp, "~xxx~", 0, sPath);

file.Open(sPath, CFile::modeReadWrite);


TCHAR sz[1024];
int nCount = 0;
do
{
nCount = pFile->Read(sz, 1023);
file.Write(sz, nCount);
}
while (nCount > 0);

file.Flush();
file.Close();


pFile->Close();
pServer->Close();
}
catch (CInternetException* pEx)
{
// catch errors from WinINet
TCHAR szErr[1024];
pEx->GetErrorMessage(szErr, 1024);

ASSERT(0);
pEx->Delete();
}

if (pFile != NULL)
{
delete pFile;
}

if (pServer != NULL)
{
delete pServer;
}

session.Close();

return sPath;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
waseemanisCommented:
AndersonAdrian,
I think if the guy has already gone to the extent of opening a remote file and written to it, then he sure must be knowing how to download and upload it !!

So is it really the answer !!???!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.