大家好,最近开发一款在windowsmobile平台上用的ftp客户端,遇到问题了。
当我连接到ftp服务器上后,调用FtpOpenFile或者FtpPutFile以及FtpGetFile都是失败,错误码是12003.我在网上看了很多
帖子,大家都有类似问题,说是路径问题。但是我确定路径是正确的.因为下面四个函数都可以正常工作
// FtpDeleteFile(hConnect,L"/test.txt");
// FtpCreateDirectory(hConnect,L"/hello");
//FtpRemoveDirectory(hConnect,L"/test");
//FtpRenameFile(hConnect,L"/hello/test.txt",L"chen.txt");我用其它的FTP客户端是可以正常上传下载的(网络没问题)
这下面是我的代码,请大家指教:
UINT myNetwork::ftpUploadThread()//ftp上传文件线程
{BOOL bRes; HINTERNET hInternet;
HINTERNET hConnect; hInternet = InternetOpen(L"ftptest", INTERNET_OPEN_TYPE_DIRECT,
NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE); if ( NULL == hInternet )
{
OutputDebugString( L"InternetOpen Error");
return 0;
} hConnect = InternetConnect(hInternet,L"221.189.8.133",
12593, L"abc", L"123456",
INTERNET_SERVICE_FTP,
INTERNET_FLAG_EXISTING_CONNECT || INTERNET_FLAG_PASSIVE,0 ); if ( NULL == hConnect )
{
OutputDebugString( L"\n====hConnect Error:%d\n" );
InternetCloseHandle(hInternet);
return 0;
} //TCHAR path[200];
bool value = false;
//memset(path,0,200);
//value=FtpSetCurrentDirectory(hConnect,L"/hello");
CString path;
path.Empty();
// value=FtpGetCurrentDirectory(hConnect,path.GetBuffer(),(LPDWORD)(30));
if(value==true)
{
// MessageBox(NULL,path,_T("mypath"), MB_OK);
}
else
{
// MessageBox(NULL,L"fail",_T("mypath"), MB_OK);
} //判断要上传的文件是否存在
CFile fileCatalog;
bRes = fileCatalog.Open(L"C:\\test.txt",CFile::modeReadWrite);
if(bRes ==false)
{
OutputDebugString( L"open local file Error is :\n");
TCHAR pVar[50];
memset(pVar,0,50);
wsprintf(pVar,_T("%d"),GetLastError());
OutputDebugString( pVar);
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
return 0;
}
else
{
OutputDebugString( L"open local file successfully\n");
fileCatalog.Close();
}
// FtpDeleteFile(hConnect,L"/test.txt");
// FtpCreateDirectory(hConnect,L"/hello");
//FtpRemoveDirectory(hConnect,L"/test");
//FtpRenameFile(hConnect,L"/hello/test.txt",L"chen.txt");
HINTERNET re =NULL;
re=FtpOpenFile(hConnect,L"/test.txt",GENERIC_READ,FTP_TRANSFER_TYPE_BINARY,0);
if ( re ==NULL )
{ OutputDebugString( L"++++++++FtpOpenFile Error is \n");
TCHAR pVar[50];
memset(pVar,0,50);
wsprintf(pVar,L"%d",GetLastError());
OutputDebugString( pVar); }
else
{
OutputDebugString( L"+++++++++FtpPutFile Success!\n" );
} bRes = FtpPutFile(hConnect,L"C:\\test.txt",L"/test.txt", FTP_TRANSFER_TYPE_ASCII, 0);
if ( bRes == 0 )
{ OutputDebugString( L"<><><><><>FtpPutFile Error is \n");
TCHAR pVar[50];
memset(pVar,0,50);
wsprintf(pVar,L"%d",GetLastError());
OutputDebugString( pVar); }
else
{
OutputDebugString( L"FtpPutFile Success!\n" );
} InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet); return 1;
}原因一直找不到,请各位大大帮忙分析下。
当我连接到ftp服务器上后,调用FtpOpenFile或者FtpPutFile以及FtpGetFile都是失败,错误码是12003.我在网上看了很多
帖子,大家都有类似问题,说是路径问题。但是我确定路径是正确的.因为下面四个函数都可以正常工作
// FtpDeleteFile(hConnect,L"/test.txt");
// FtpCreateDirectory(hConnect,L"/hello");
//FtpRemoveDirectory(hConnect,L"/test");
//FtpRenameFile(hConnect,L"/hello/test.txt",L"chen.txt");我用其它的FTP客户端是可以正常上传下载的(网络没问题)
这下面是我的代码,请大家指教:
UINT myNetwork::ftpUploadThread()//ftp上传文件线程
{BOOL bRes; HINTERNET hInternet;
HINTERNET hConnect; hInternet = InternetOpen(L"ftptest", INTERNET_OPEN_TYPE_DIRECT,
NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE); if ( NULL == hInternet )
{
OutputDebugString( L"InternetOpen Error");
return 0;
} hConnect = InternetConnect(hInternet,L"221.189.8.133",
12593, L"abc", L"123456",
INTERNET_SERVICE_FTP,
INTERNET_FLAG_EXISTING_CONNECT || INTERNET_FLAG_PASSIVE,0 ); if ( NULL == hConnect )
{
OutputDebugString( L"\n====hConnect Error:%d\n" );
InternetCloseHandle(hInternet);
return 0;
} //TCHAR path[200];
bool value = false;
//memset(path,0,200);
//value=FtpSetCurrentDirectory(hConnect,L"/hello");
CString path;
path.Empty();
// value=FtpGetCurrentDirectory(hConnect,path.GetBuffer(),(LPDWORD)(30));
if(value==true)
{
// MessageBox(NULL,path,_T("mypath"), MB_OK);
}
else
{
// MessageBox(NULL,L"fail",_T("mypath"), MB_OK);
} //判断要上传的文件是否存在
CFile fileCatalog;
bRes = fileCatalog.Open(L"C:\\test.txt",CFile::modeReadWrite);
if(bRes ==false)
{
OutputDebugString( L"open local file Error is :\n");
TCHAR pVar[50];
memset(pVar,0,50);
wsprintf(pVar,_T("%d"),GetLastError());
OutputDebugString( pVar);
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
return 0;
}
else
{
OutputDebugString( L"open local file successfully\n");
fileCatalog.Close();
}
// FtpDeleteFile(hConnect,L"/test.txt");
// FtpCreateDirectory(hConnect,L"/hello");
//FtpRemoveDirectory(hConnect,L"/test");
//FtpRenameFile(hConnect,L"/hello/test.txt",L"chen.txt");
HINTERNET re =NULL;
re=FtpOpenFile(hConnect,L"/test.txt",GENERIC_READ,FTP_TRANSFER_TYPE_BINARY,0);
if ( re ==NULL )
{ OutputDebugString( L"++++++++FtpOpenFile Error is \n");
TCHAR pVar[50];
memset(pVar,0,50);
wsprintf(pVar,L"%d",GetLastError());
OutputDebugString( pVar); }
else
{
OutputDebugString( L"+++++++++FtpPutFile Success!\n" );
} bRes = FtpPutFile(hConnect,L"C:\\test.txt",L"/test.txt", FTP_TRANSFER_TYPE_ASCII, 0);
if ( bRes == 0 )
{ OutputDebugString( L"<><><><><>FtpPutFile Error is \n");
TCHAR pVar[50];
memset(pVar,0,50);
wsprintf(pVar,L"%d",GetLastError());
OutputDebugString( pVar); }
else
{
OutputDebugString( L"FtpPutFile Success!\n" );
} InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet); return 1;
}原因一直找不到,请各位大大帮忙分析下。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货