#include<windows.h>
#include<wininet.h>
#include<iostream>
#include <fstream>
#include <string>
#include <cstdio>
using namespace std;
void main(int argc, char *argv[])
{
string host, username, password;
host = "localhost";
username = "dahaka";
password = "1234";
// Initialize WinInet
HINTERNET hSession = InternetOpenA("FtpCmd Utility",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
0);
// Setup connection
HINTERNET hConnection = InternetConnectA(hSession,
host.c_str(),
INTERNET_DEFAULT_FTP_PORT,
username.c_str(),
password.c_str(),
INTERNET_SERVICE_FTP,
0,
NULL);
HINTERNET hResponse;
BOOL bRet = FtpCommandA(hConnection,
TRUE,
FTP_TRANSFER_TYPE_BINARY,
"RETR /op.wmv",
0,
&hResponse);
InternetCloseHandle(hResponse);
InternetCloseHandle(hConnection);
InternetCloseHandle(hSession);
system("pause");
}
在FtpCommand函数时,当我发送RETR命令的时候,总是出现异常:
Unhandled exception at 0x76c9d193 in FTPwininet.exe: 0xC0000005: Access violation reading location 0x00000001.
我本地使用的FTP服务器是Filezilla 0.9.33 beta版本,在服务器那边的相关日志如下:
(000037) 2010/10/14 14:12:44 - dahaka (127.0.0.1)> TYPE I
(000037) 2010/10/14 14:12:44 - dahaka (127.0.0.1)> 200 Type set to I
(000037) 2010/10/14 14:12:44 - dahaka (127.0.0.1)> PORT 127,0,0,1,56,220
(000037) 2010/10/14 14:12:44 - dahaka (127.0.0.1)> 200 Port command successful
说明传输模式设置好了、数据端口也打开了但是就是没有传输数据,程序这边的winInet就出错了,很是奇怪。。
但是之前使用的时候没有出现这种情况。。。。我用的是VS2010的环境
求教各位这是什么情况、、、