大家好,最近开发一款在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;
}原因一直找不到,请各位大大帮忙分析下。

解决方案 »

  1.   

    自己顶,请问有人知道这个问题吗?是函数本身的bug还是其它原因?
      

  2.   

    有高手指点一下吗?一直找不到原因.我用vc自带的列子build后也是出现12003 错误,但是网上下载的cuteftp工具却可以使用.请各位高手指点
      

  3.   

    终于解决了,原来是wininet函数本身的问题。只要服务器不是微软的服务器,就可能出现上面的情况。
      

  4.   

    当我把这个程序移植到windowsmobile 6.5系统的手机上,又出现同样的现象了。FtpDeleteFile这些函数可以正常使用,但是FtpPutFile(hConnect,L"abc.txt",L"abc.txt", FTP_TRANSFER_TYPE_ASCII, 0);又出现12003错误了,各位高手指点下哈
      

  5.   

    这个你是不是去Mobile的专区问问