ftp help 
Author Message
 ftp help

I am adding FTP function to my application.  I just want to download a file
from FTP server only.  I am using EVC3.0 and Pocket PC 2002 emulator only.
I am trying to use the flow: InternetOpen -> InternetConnect ->
FtpOpenFiile -> InternetReadFile -> InternetClosehandle.

I have several questions:
1.) When I run the following code in Debug mode, line 10 success (i guess)
since it returns a non-NULL handle (0x00cc0004), but when i call
GetLastError() in line 11, lerror = 87, is it normal?

2.) Then in line 14, I get another handle (0x00cc0008), get lerror in line
15 = 10042, what does it means?

3.) Then FtpOpenFile fail since it returns NULL, lerror (line 23) = 6, what
does it means?

I am sure there is the file on the server.
Anyone can help??
Thx.

1    LPCTSTR ClientApp = _T("FTP");
2    LPCTSTR REMOTEFile = _T("remotefile");
3    LPCTSTR LOCALFile = _T("localfile");
4    LPCTSTR FTPServer = _T("xxx.xxx.xxx.xxxx");
5    LPCTSTR username = _T("xxxxxxx");
6    LPCTSTR password = _T("xxxxxxxx");

7    HINTERNET hinternet = NULL;
8    HINTERNET hSecondary = NULL;

9    lerror = GetLastError();

10    hinternet = InternetOpen(ClientApp, INTERNET_OPEN_TYPE_DIRECT, 0, 0,
0);
11    lerror = GetLastError();
12    if (NULL == hinternet)
13        MessageBox(TEXT("Could not open internet session") ,
TEXT("Error"), MB_OK | MB_ICONERROR);

14    hSecondary = InternetConnect(hinternet, FTPServer,
INTERNET_DEFAULT_FTP_PORT, username, password,
INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, NULL);
15    lerror = GetLastError();
16    if (NULL == hSecondary)
17        MessageBox(TEXT("Could not connect Internet") , TEXT("Error"),
MB_OK | MB_ICONERROR);

18    HINTERNET localfile = CreateFile(LOCALFile, GENERIC_WRITE,
FILE_SHARE_WRITE, NULL,
                                                        CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
19    lerror = GetLastError();

20    HINTERNET ftpfile = FtpOpenFile(hSecondary, REMOTEFile, GENERIC_READ,

FTP_TRANSFER_TYPE_BINARY, NULL );
21    if (ftpfile == NULL)
22          MessageBox(TEXT("FtpOpenFile fail"), TEXT("Error"), MB_OK |
MB_ICONERROR);
23    lerror = GetLastError();

24    bool IRF = true;
25    IRF = InternetReadFile(ftpfile, buff, 128*128*128, 0);
26    lerror = GetLastError();
27    if (IRF == false)
28    MessageBox(TEXT("InternetReadFileFail!"), TEXT("Error"), MB_OK |
MB_ICONERROR);

29    InternetCloseHandle(ftpfile);
30    InternetCloseHandle(localfile);
31    InternetCloseHandle(hinternet);
32    InternetCloseHandle(hSecondary);



Mon, 26 Sep 2005 15:21:17 GMT  
 ftp help
I think that the sequence that you want is actually:

 InternetOpen()
 InternetConnect()
 FtpGetFile()
 InternetCloseHandle();
 InternetCloseHandle();

As far as your questions:

1) Don't call GetLastError() when no error was indicated.

2) Same.  Don't pay any attention to GetLastError() unless an error is
indicated.  Its value might be *anything*.

3) Error codes returned by GetLastError() are found in winerror.h.

Paul T.


Quote:
> I am adding FTP function to my application.  I just want to download a
file
> from FTP server only.  I am using EVC3.0 and Pocket PC 2002 emulator only.
> I am trying to use the flow: InternetOpen -> InternetConnect ->
> FtpOpenFiile -> InternetReadFile -> InternetClosehandle.

> I have several questions:
> 1.) When I run the following code in Debug mode, line 10 success (i guess)
> since it returns a non-NULL handle (0x00cc0004), but when i call
> GetLastError() in line 11, lerror = 87, is it normal?

> 2.) Then in line 14, I get another handle (0x00cc0008), get lerror in line
> 15 = 10042, what does it means?

> 3.) Then FtpOpenFile fail since it returns NULL, lerror (line 23) = 6,
what
> does it means?

> I am sure there is the file on the server.
> Anyone can help??
> Thx.

> 1    LPCTSTR ClientApp = _T("FTP");
> 2    LPCTSTR REMOTEFile = _T("remotefile");
> 3    LPCTSTR LOCALFile = _T("localfile");
> 4    LPCTSTR FTPServer = _T("xxx.xxx.xxx.xxxx");
> 5    LPCTSTR username = _T("xxxxxxx");
> 6    LPCTSTR password = _T("xxxxxxxx");

> 7    HINTERNET hinternet = NULL;
> 8    HINTERNET hSecondary = NULL;

> 9    lerror = GetLastError();

> 10    hinternet = InternetOpen(ClientApp, INTERNET_OPEN_TYPE_DIRECT, 0, 0,
> 0);
> 11    lerror = GetLastError();
> 12    if (NULL == hinternet)
> 13        MessageBox(TEXT("Could not open internet session") ,
> TEXT("Error"), MB_OK | MB_ICONERROR);

> 14    hSecondary = InternetConnect(hinternet, FTPServer,
> INTERNET_DEFAULT_FTP_PORT, username, password,
> INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, NULL);
> 15    lerror = GetLastError();
> 16    if (NULL == hSecondary)
> 17        MessageBox(TEXT("Could not connect Internet") , TEXT("Error"),
> MB_OK | MB_ICONERROR);

> 18    HINTERNET localfile = CreateFile(LOCALFile, GENERIC_WRITE,
> FILE_SHARE_WRITE, NULL,
>                                                         CREATE_ALWAYS,
> FILE_ATTRIBUTE_NORMAL, NULL);
> 19    lerror = GetLastError();

> 20    HINTERNET ftpfile = FtpOpenFile(hSecondary, REMOTEFile,
GENERIC_READ,

> FTP_TRANSFER_TYPE_BINARY, NULL );
> 21    if (ftpfile == NULL)
> 22          MessageBox(TEXT("FtpOpenFile fail"), TEXT("Error"), MB_OK |
> MB_ICONERROR);
> 23    lerror = GetLastError();

> 24    bool IRF = true;
> 25    IRF = InternetReadFile(ftpfile, buff, 128*128*128, 0);
> 26    lerror = GetLastError();
> 27    if (IRF == false)
> 28    MessageBox(TEXT("InternetReadFileFail!"), TEXT("Error"), MB_OK |
> MB_ICONERROR);

> 29    InternetCloseHandle(ftpfile);
> 30    InternetCloseHandle(localfile);
> 31    InternetCloseHandle(hinternet);
> 32    InternetCloseHandle(hSecondary);



Tue, 27 Sep 2005 04:31:27 GMT  
 ftp help
FtpGetFile and FtpPutFile functions have a bug:
http://support.microsoft.com/default.aspx?scid=KB;EN-
US;Q312039&
To around this issue this page tells us to use FtpOpenFile
and InternetReadFile just to read the file and WriteFile
to copy it locally. But when I call FtpOpenFile it always
return NULL and GetLastError returns 12031,
ERROR_INTERNET_CONNECTION_RESET.
Why does always return this error?

Quote:
>-----Original Message-----
>I think that the sequence that you want is actually:

> InternetOpen()
> InternetConnect()
> FtpGetFile()
> InternetCloseHandle();
> InternetCloseHandle();

>As far as your questions:

>1) Don't call GetLastError() when no error was indicated.

>2) Same.  Don't pay any attention to GetLastError()
unless an error is
>indicated.  Its value might be *anything*.

>3) Error codes returned by GetLastError() are found in
winerror.h.

>Paul T.



>> I am adding FTP function to my application.  I just
want to download a
>file
>> from FTP server only.  I am using EVC3.0 and Pocket PC
2002 emulator only.
>> I am trying to use the flow: InternetOpen ->
InternetConnect ->
>> FtpOpenFiile -> InternetReadFile -> InternetClosehandle.

>> I have several questions:
>> 1.) When I run the following code in Debug mode, line

10 success (i guess)

- Show quoted text -

Quote:
>> since it returns a non-NULL handle (0x00cc0004), but
when i call
>> GetLastError() in line 11, lerror = 87, is it normal?

>> 2.) Then in line 14, I get another handle (0x00cc0008),
get lerror in line
>> 15 = 10042, what does it means?

>> 3.) Then FtpOpenFile fail since it returns NULL, lerror
(line 23) = 6,
>what
>> does it means?

>> I am sure there is the file on the server.
>> Anyone can help??
>> Thx.

>> 1    LPCTSTR ClientApp = _T("FTP");
>> 2    LPCTSTR REMOTEFile = _T("remotefile");
>> 3    LPCTSTR LOCALFile = _T("localfile");
>> 4    LPCTSTR FTPServer = _T("xxx.xxx.xxx.xxxx");
>> 5    LPCTSTR username = _T("xxxxxxx");
>> 6    LPCTSTR password = _T("xxxxxxxx");

>> 7    HINTERNET hinternet = NULL;
>> 8    HINTERNET hSecondary = NULL;

>> 9    lerror = GetLastError();

>> 10    hinternet = InternetOpen(ClientApp,

INTERNET_OPEN_TYPE_DIRECT, 0, 0,
Quote:
>> 0);
>> 11    lerror = GetLastError();
>> 12    if (NULL == hinternet)
>> 13        MessageBox(TEXT("Could not open internet
session") ,
>> TEXT("Error"), MB_OK | MB_ICONERROR);

>> 14    hSecondary = InternetConnect(hinternet, FTPServer,
>> INTERNET_DEFAULT_FTP_PORT, username, password,
>> INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, NULL);
>> 15    lerror = GetLastError();
>> 16    if (NULL == hSecondary)
>> 17        MessageBox(TEXT("Could not connect

Internet") , TEXT("Error"),

- Show quoted text -

Quote:
>> MB_OK | MB_ICONERROR);

>> 18    HINTERNET localfile = CreateFile(LOCALFile,
GENERIC_WRITE,
>> FILE_SHARE_WRITE, NULL,

CREATE_ALWAYS,
>> FILE_ATTRIBUTE_NORMAL, NULL);
>> 19    lerror = GetLastError();

>> 20    HINTERNET ftpfile = FtpOpenFile(hSecondary,
REMOTEFile,
>GENERIC_READ,

>> FTP_TRANSFER_TYPE_BINARY, NULL );
>> 21    if (ftpfile == NULL)
>> 22          MessageBox(TEXT("FtpOpenFile fail"), TEXT
("Error"), MB_OK |
>> MB_ICONERROR);
>> 23    lerror = GetLastError();

>> 24    bool IRF = true;
>> 25    IRF = InternetReadFile(ftpfile, buff,
128*128*128, 0);
>> 26    lerror = GetLastError();
>> 27    if (IRF == false)
>> 28    MessageBox(TEXT("InternetReadFileFail!"), TEXT
("Error"), MB_OK |
>> MB_ICONERROR);

>> 29    InternetCloseHandle(ftpfile);
>> 30    InternetCloseHandle(localfile);
>> 31    InternetCloseHandle(hinternet);
>> 32    InternetCloseHandle(hSecondary);

>.



Sat, 01 Oct 2005 00:03:57 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. FTP help needed

2. Ftp Help needed. CFtpConnection

3. Ftp Help

4. FTP Help Urgent

5. MS quick C for windows, how to build library? ftp help file?

6. Sending messages to FTP client from FTP Server applications

7. Virtual FTP Directories with FTP functions

8. Help - FTP header file

9. Help with custom FTP program

10. Help with simple FTP daemon

11. Compiler for C-help to find an ftp site

12. help w/writing automated ftp script

 

 
Powered by phpBB® Forum Software