1
我为应用程序写了一个dll,它将通过ftp从应用程序上传一些信息到服务器。上传的大部分文件都能正常上传。CInternetSession :: WriteString写入文件并直接删除
有一个文件将完全上传,但上传之后直接从服务器上删除(这种情况不总是发生,有时该文件在上传后存在于服务器上)。该文件大约400 kb,其他所有文件都较小。
日期和类型是两个CStrings。数据包含文件内容并键入文件名的第一部分。
CInternetSession session(_T("whtsnXt_dll"));
CFtpConnection* pServer = NULL;
CInternetFile* pFile = NULL;
LPCTSTR pszServerName = _T("servername");
CString fileName = type + L".txt";
int curPos = 0;
CString postData = data;
try
{
CString strServerName;
INTERNET_PORT nPort = 21;
pServer = session.GetFtpConnection(pszServerName, _T("username"), _T("password"), nPort, TRUE);
if (pServer->SetCurrentDirectory(L"goes") == 0) {
// MessageBox::Show("De map bestaat niet", "whtsnXt error", MessageBoxButtons::OK, MessageBoxIcon::Error);
}
pFile = pServer->OpenFile((LPCTSTR)fileName, GENERIC_WRITE);
pFile->WriteString(postData);
pFile->Close();
pServer->Close();
delete pFile;
delete pServer;
}
catch (CInternetException* pEx)
{
//catch errors from WinInet
TCHAR pszError[64];
pEx->GetErrorMessage(pszError, 64);
MessageBox::Show(gcnew String(pszError), "whtsnXt error", MessageBoxButtons::OK, MessageBoxIcon::Error);
}
session.Close();
有人知道一种方法来直接上传该文件,直接删除?
测试时文件名是否有所不同? – thomiel 2015-02-07 10:32:29
有不同的文件上传与所有不同的名称。但他们在一起总是有相同的名字(出错的文件是rooster0.txt)。该文件在上传过程中和上传后被覆盖(当文件存在时) – 2015-02-07 13:56:30
您是否测试了另一个ftp服务器? – thomiel 2015-02-07 16:56:15