FtpGetFile WinINEt 永不返回
FtpGetFile WinINEt never returns
我遇到了一个奇怪的问题(很奇怪,让我说呵呵)。在 EXE 文件 (24 MB) 的 FTP 下载期间,如果连接中断,则似乎是 WinINEt 库的函数 FtpGetFile 存在错误,并且永远不会返回。这会导致将来的文件传输失败(连接已打开)。显然,我通过增加服务器传输的超时找到了解决方法,但我不喜欢它。我没有通过谷歌搜索发现类似的问题(也许我引入了错误的关键字)。
我在互联网上阅读了一些论坛,似乎每个人都不建议使用 FtpGetFile,因为它有问题。
这出现在具有很大滞后(并非总是如此)的网络场景中,但在良好条件下它会消失(下载正确进行并且 FtpGetFile 始终返回)。
以下是我如何使用该功能:
if( FtpGetFile(m_hFtpSession, strSourcePath.c_str(), strTargetPath.c_str(), 0, 0, FTP_TRANSFER_TYPE_BINARY, 0)==TRUE)
谁能证实这一点?我应该重构我的代码并寻找更新吗?
谢谢
我找到了一种不使用FtpGetFile下载文件的方法。我希望这段代码可以帮助某人:
bool RetrieveFile(const string& strSource, const string& strTarget) {
/* The handle for the transfer */
HINTERNET hTransfer = NULL;
/*
* Set default error
*/
DWORD error = ERROR_SUCCESS;
if( !isConnected ) {
debug("%s(): ERROR not connectedn", __FUNCTION__);
return false;
}
/* Initiate access to a remote FTP connection */
hTransfer = FtpOpenFile(hFtpSession, strSource.c_str(), GENERIC_READ,
FTP_TRANSFER_TYPE_BINARY, 0);
if(hTransfer) {
std::ofstream myostream(strTarget.c_str(), std::ios::binary);
if ( myostream.is_open() ) {
static const DWORD SIZE = 1024;
BYTE data[SIZE];
DWORD size = 0;
do {
BOOL result = InternetReadFile(hTransfer, data, SIZE, &size);
if ( result == FALSE ) {
error = GetLastError();
Debug("InternetReadFile(): %lun", error);
}
myostream.write((const char*)data, size);
}
while ((error == ERROR_SUCCESS) && (size > 0));
// Close the stream
myostream.close();
}
else {
Debug("Could not open '%s'.n", strTarget.c_str());
error = ERROR_FILE_NOT_FOUND; // Not necessarily not found, but it is to describe a file error which is different from ERROR_SUCCESS
}
// Close
const BOOL result = InternetCloseHandle(hTransfer);
if ( result == FALSE ) {
const DWORD error = GetLastError();
debug("InternetClose(): %lun", error);
}
/* Check error status of the process */
return (error == ERROR_SUCCESS);
}
DWORD dwInetError;
DWORD dwExtLength = 1000;
TCHAR *szExtErrMsg = NULL;
TCHAR errmsg[1000];
szExtErrMsg = errmsg;
int returned = InternetGetLastResponseInfo( &dwInetError, szExtErrMsg, &dwExtLength );
debug("dwInetError: %d Returned: %dn", dwInetError, returned);
debug("Buffer: %sn", szExtErrMsg);
debug("%s() : ERROR to get '%s' file (errorCode=%d)n", __FUNCTION__, strSource.c_str(), GetLastError());
return false;
}
相关文章:
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- 什么时候在C++中返回常量引用是个好主意
- 你能重载对象变量名本身返回的内容吗
- 为什么 Serial.println(<char[]>);返回随机字符?
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 如何获取std::result_of函数的返回类型
- QueryWorkingSet总是返回false
- (C++)分析树以计算返回错误值的简单算术表达式
- 访问者访问变体并返回不同类型时出错
- 如何返回一个类的两个对象相加的结果
- OpenInventor从9.8升级到10.4.2后,GLSL纹理返回零
- lower_bound()返回最后一个元素
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 如何取消对nullptr的屏蔽,返回正确的对象
- 奇怪的结构&GCC&clang(void*返回类型)
- 架构决策:返回std::future还是提供回调
- FtpGetFile WinINEt 永不返回
- WinInet InternetReadFile返回0x8007007a(传递给系统调用的数据区域太小)
- WinInet HttpQuery信息返回无效状态码