RE: question using FtpGetFile



You are receiving the three unresolved symbol error because you are not
linking to wininet.lib. In order to resolve those you will need to add
wininet.lib to the list of libraries that your project is linking.

That should resolve you compile errors, however GetFile is not going to
work for you because you are trying to download from a web server
(http://openwebmail.org/) and not an FTP server.

The GetFile example is only for downloading a file from an FTP server. In
order to download a file from a web server you will need to use the WinInet
functions InternetOpenUrl and InternetReadFile, which will allow you to
download files from a Web or FTP server.


Here is a little code snippet that should get you started.




#define READ_BUFFER 1024

...


CHAR buffer[READ_BUFFER + 1];
DWORD dwBufferSize = READ_BUFFER;
DWORD dwBytesRead = 0;

HINTERNET hRoot;
HINTERNET hOpen;

hRoot = InternetOpen( TEXT("agent") , // user agent
INTERNET_OPEN_TYPE_DIRECT, // access type
NULL, // proxy server
NULL, // proxy bypass list
0 // flags
);

if ( ! hRoot )
{
//quit because InternetOpen failed
return;
}

hOpen = InternetOpenUrl(hRoot, // handle returned from InternetOpen
TEXT("http://openwebmail.org/openwebmail/doc/changes.txt";), //url
NULL, // extra headers
0, // length of extra headers
0, // flags
0 // context, for async calls
);

if ( ! hOpen )
{
//quit because InternetOpenUrl failed
InternetCloseHandle( hRoot );
return;
}

dwBytesRead = 1;

while ( dwBytesRead != 0 && InternetReadFile( hOpen, buffer, dwBufferSize,
&dwBytesRead ) )
{
// do something with the dwByteRead of information that was just
// read in to buffer because it will be overwritten on the
// next iteration of the loop, like write it to a file.

}


if ( hRoot )
{
InternetCloseHandle( hRoot );
}





Garret Magin
Software Design Engineer/Test, Windows CE
Microsoft Corporation

----
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
>From: "paul" <chu2802@xxxxxxxxx>
>Subject: question using FtpGetFile
>Date: Sun, 15 Jan 2006 10:24:33 +0800
>Lines: 100
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
>Message-ID: <etMhMrXGGHA.3896@xxxxxxxxxxxxxxxxxxxx>
>Newsgroups: microsoft.public.windowsce.embedded.vc
>NNTP-Posting-Host: 221.126.226.154
>Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
>Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.windowsce.embedded.vc:43577
>X-Tomcat-NG: microsoft.public.windowsce.embedded.vc
>
>hi all,
>the below code is just the example given in evc4 about the use of ftp to
get
>a file with some error-out statements shorted. i think that should work.
But
>i wonder where to place the function? is that ok just to place it at the
>back of the file?
>
>~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
>int WINAPI GetFile(HWND hX, HINTERNET hConnect)
>{
> TCHAR strInFile[80];
> TCHAR strOutFile[80];
> int intTransType;
>
> GetDlgItemText(hX,IDC_DXF_NAV,strOutFile,80);
> GetDlgItemText(hX,IDC_DXF_NAV,strInFile,80);
>
> if ((_tcslen(strOutFile)==0) | (_tcslen(strInFile)==0))
> {
> MessageBox(hX,_T("Target File or Destination File Missing"),_T("Get
>File"),MB_OK);
> return 0;
> }
> else
> {
> intTransType = MessageBox(hX,
> _T("Do you want to download in ASCII (Default:Binary)?"),
> _T("Get File"),MB_YESNO);
> if (intTransType==IDYES)
> {
> if(!FtpGetFile(hConnect,strInFile,strOutFile,FALSE,
> FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_ASCII |
> INTERNET_FLAG_NO_CACHE_WRITE,0))
> {
>// ErrorOut(hX,GetLastError(),"Get File");
> // DisplayDir(hX,INTERNET_FLAG_RELOAD);
> return 0;
> }
> else
> {
> MessageBox(hX,_T("ASCII Transfer Complete"),_T("Get
>File"),MB_OK);
> return 1;
> }
> }
> else
> {
> if(!FtpGetFile(hConnect,strInFile,strOutFile,FALSE,
> FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY |
> INTERNET_FLAG_RELOAD,0))
> {
>// ErrorOut(hX,GetLastError(),"Get File");
> return 0;
> }
> else
> {
> MessageBox(hX,_T("Binary Transfer Complete"),_T("Get
>File"),MB_OK);
> return 1;
> }
> }
> }
>}
>~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
>
>after that, when i want to trigger the function, i use the following the
>code, is that written correct? also, is the POSITION where i place the code
>correct? because i get three unresolved external.............
>Linking...
>dxf_nav.obj : error LNK2019: unresolved external symbol
>__imp__InternetConnectW referenced in function "long __cdecl WndProc(struct
>HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YAJPAUHWND__@@IIJ@Z)
>dxf_nav.obj : error LNK2019: unresolved external symbol
__imp__InternetOpenW
>referenced in function "long __cdecl WndProc(struct HWND__ *,unsigned
>int,unsigned int,long)" (?WndProc@@YAJPAUHWND__@@IIJ@Z)
>dxf_nav.obj : error LNK2019: unresolved external symbol __imp__FtpGetFileW
>referenced in function "int __cdecl GetFile(struct HWND__ *,void *)"
>(?GetFile@@YAHPAUHWND__@@PAX@Z)
>emulatorRel/dxf_nav.exe : fatal error LNK1120: 3 unresolved externals
>
>~*~*~*~*~*~*~*~~*~*~~*~*~*~*~
>LRESULT CALLBACK WndProc
> switch (message)
> case WM_COMMAND:
> switch (wmId)
> case IDM_OPEN:
> {
> HINTERNET hOpen = NULL, hConnect = NULL;
> hOpen =
>InternetOpen(TEXT("Example"),INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
> hConnect = InternetConnect (hOpen,
>
>_T("http://openwebmail.org/openwebmail/doc/changes.txt";),
> INTERNET_DEFAULT_HTTP_PORT,
> NULL, NULL,
> INTERNET_SERVICE_FTP,
> 0, 0);
> GetFile(hWnd,hConnect);
> }
>
>
>

.



Relevant Pages

  • Re: Downloads Fail With IIS 6.0
    ... isn't very secure. ... we would have to rewrite many pages of our web ... > would recommend to set up a FTP server and put that file on it. ... >> appear to download, and show the correct number of pages, but have all blank ...
    (microsoft.public.inetserver.iis)
  • Re: clientless windowsbased sftp / ssh server?
    ... > maybe run a secure http webserver instead of ftp server since ie6 ... > webserver then I think I can only download from it, ... No, you can upload too. ...
    (comp.security.ssh)
  • Re: Software Product Download and FTP
    ... Have you looked into possibly writing a Perl script in the cgi-bin directory ... connect to the FTP server? ... Software Product Download and FTP ...
    (Security-Basics)
  • Re: [SLE] I need your help please
    ... Taylor, Phillip wrote: ... Does the ftp server come with This ... Failing that, download the packages ...
    (SuSE)
  • unable to install from floppies
    ... I am tyring to install from the floppies. ... I get to the point were I choose the ftp server to d/l from. ... then it says can't resolve the ftp.freebsd.org or any of the servers. ...
    (freebsd-questions)