我们有一段代码可以在 ftp 服务器上上传/下载和列出文件。它使用 WinInet 来处理 FTP 命令。它已经工作了好几年了。但是,在 Windows 8.1 和带有 IE 11 的 Windows 7 中,相同的代码有时会返回错误 12003。ftp 服务器日志中没有错误。
简单函数用于检查 FTP 响应中是否有错误
bool IsLastErrorReallyAnError()
{
int err = GetLastError();
bool isError = true;
if (err == ERROR_INTERNET_EXTENDED_ERROR)
{
isError = false;
DWORD error, size = 0;
::InternetGetLastResponseInfo(&error, NULL, &size);
std::vector<wchar_t> response(size+1);
::InternetGetLastResponseInfo(&error, &response[0], &size);
utils::trace("Backup", "Checking FTP respose", &response[0]);
std::vector<std::wstring> lines;
boost::split(lines, std::wstring(&response[0]), boost::is_any_of(L"\n"));
for (auto it = lines.cbegin(); it != lines.cend(); ++it)
{
// If some response starts with 5хх then it is real error
if (boost::starts_with(*it,L"5"))
{
utils::trace("Backup", "Real FTP error", &((*it)[0]));
isError = true;
break;
}
}
if (!isError)
{
utils::trace("Backup", "Checking FTP respose ", L"false error!");
}
}
return isError;
}
在我们程序的日志中,我们得到
05:56:43.680 0x21c ERR CFtpFileSystem CFtpFileSystem::TryOpenBinaryFile: FtpOpenFileW error 12003
05:56:43.680 0x21c INF Backup Checking FTP respose: 226 Transfer OK
200 Type set to I
05:56:43.680 0x21c INF Backup Checking FTP respose : false error!
在 FTP 服务器日志中(它有不同的时区):
(000445)30.10.2013 16:56:23 - (not logged in) (10.16.83.3)> Connected, sending welcome message...
(000445)30.10.2013 16:56:23 - (not logged in) (10.16.83.3)> 220-FileZilla Server version 0.9.41 beta
(000445)30.10.2013 16:56:23 - (not logged in) (10.16.83.3)> 220-written by Tim Kosse (Tim.Kosse@gmx.de)
(000445)30.10.2013 16:56:23 - (not logged in) (10.16.83.3)> 220 Please visit http://sourceforge.net/projects/filezilla/
(000445)30.10.2013 16:56:29 - (not logged in) (10.16.83.3)> USER test
(000445)30.10.2013 16:56:29 - (not logged in) (10.16.83.3)> 331 Password required for test
(000445)30.10.2013 16:56:35 - (not logged in) (10.16.83.3)> PASS ****
(000445)30.10.2013 16:56:35 - test (10.16.83.3)> 230 Logged on
(000445)30.10.2013 16:56:43 - test (10.16.83.3)> TYPE I
(000445)30.10.2013 16:56:43 - test (10.16.83.3)> 200 Type set to I
(000445)30.10.2013 16:56:43 - test (10.16.83.3)> PASV
(000445)30.10.2013 16:56:43 - test (10.16.83.3)> 227 Entering Passive Mode (10,16,82,191,238,169)
(000445)30.10.2013 16:56:43 - test (10.16.83.3)> STOR /srv-test/0f0c04cc-c323-4bb6-a814-696fbbd695c3/527101B9/ab42ed5a-7df0-4421-a03c-d9f75891dcbf
(000445)30.10.2013 16:56:43 - test (10.16.83.3)> 150 Connection accepted
(000445)30.10.2013 16:56:43 - test (10.16.83.3)> 226 Transfer OK
(000445)30.10.2013 16:56:43 - test (10.16.83.3)> TYPE I
(000445)30.10.2013 16:56:43 - test (10.16.83.3)> 200 Type set to I
(000445)30.10.2013 16:56:43 - test (10.16.83.3)> PASV
(000445)30.10.2013 16:56:43 - test (10.16.83.3)> 227 Entering Passive Mode (10,16,82,191,238,170)
(000445)30.10.2013 16:56:56 - test (10.16.83.3)> disconnected.
任何想法如何调整 IE11 附带的 wininet 版本以摆脱此类错误?