Discussion:
async problem with FTP
(too old to reply)
Ed Debrot
2006-03-31 19:46:44 UTC
Permalink
I've had a wininet program performing for years running FTP but have
recently had a need to modify this to allow for asynchronous FTP. Extracts
of my code are shown below (stripped so don't worry about syntax). It all
works up until I call InternetReadFileEx(). This function returns FALSE and
GetLastError indicates 12018 which says that somehow that operation is
invalid on the handle I am using. I've checked this code over many times and
compared it to similar code I've researched on the internet, but I still
have the problem. I'm running this with Visual Studio 6 and plan on porting
to WinCE when I get it working in Win32. Any help would be greatly
appreciated. Just to be sure, all of my handles up until the
InternetReadFileEx() are valid (I'm using the callback to assign handles and
waiting for request completion before continuing) and if I switch
InternetReadFileEx() with InternetReadFile() it all works fine - but
InternetReadFile() does not run asynchonously. I've included a log of all
callbacks at the bottom.

thanks...

<<<<< CODE >>>>>

h_iopen = InternetOpen(agent_nam,
INTERNET_OPEN_TYPE_DIRECT,
NULL,
NULL,
INTERNET_FLAG_ASYNC);

rc = InternetSetStatusCallback(h_iopen, InternetCallback);

h_iconnect = InternetConnect(h_iopen,
ftp_addr,
INTERNET_INVALID_PORT_NUMBER,
user,
psswd,
INTERNET_SERVICE_FTP,
INTERNET_FLAG_PASSIVE,
myContext);

h_file_remote = my_FtpOpenFile(h_iconnect,
ufnam_remote,
GENERIC_READ,
FTP_TRANSFER_TYPE_ASCII
| INTERNET_FLAG_RELOAD
| INTERNET_FLAG_NO_CACHE_WRITE,
myContext;


{
INTERNET_BUFFERS ib;

memset(&ib, 0, sizeof(INTERNET_BUFFERS));
ib.dwStructSize = sizeof(INTERNET_BUFFERS);
ib.lpvBuffer = lpBuffer;
ib.dwBufferLength = dwNumberOfBytesToRead;

async_reset("InternetReadFileEx");
bVal = InternetReadFileEx(h_file_remote,
&ib,
IRF_ASYNC,
myContext);
}
bVal is returned as FALSE here,
checking getLastError() indicates error code 12018
FtpGetFile(h_iconnect,
fnam_remote,
fnam_local,
full_fnam_local,
FALSE,
0,
FTP_TRANSFER_TYPE_ASCII
| INTERNET_FLAG_RELOAD
| INTERNET_FLAG_NO_CACHE_WRITE,
myContext,
&num_bytes);



<<<<< LOG DATA >>>>>

InternetSetStatusCallback()=ok

InternetConnect
dwInternetStatus=<60>
<INTERNET_STATUS_HANDLE_CREATED>
dwInternetStatus=<10>
dwInternetStatus=<10>
dwInternetStatus=<11>
dwInternetStatus=<11>
dwInternetStatus=<20>
dwInternetStatus=<20>
dwInternetStatus=<21>
dwInternetStatus=<21>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<30>
dwInternetStatus=<30>
dwInternetStatus=<31>
dwInternetStatus=<31>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<30>
dwInternetStatus=<30>
dwInternetStatus=<31>
dwInternetStatus=<31>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<100>
<INTERNET_STATUS_REQUEST_COMPLETE>
async_complete

FtpSetCurrentDirectory
dwInternetStatus=<30>
dwInternetStatus=<30>
dwInternetStatus=<31>
dwInternetStatus=<31>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<100>
<INTERNET_STATUS_REQUEST_COMPLETE>
async_complete


FtpOpenFile
dwInternetStatus=<60>
<INTERNET_STATUS_HANDLE_CREATED>
dwInternetStatus=<30>
dwInternetStatus=<30>
dwInternetStatus=<31>
dwInternetStatus=<31>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<30>
dwInternetStatus=<30>
dwInternetStatus=<31>
dwInternetStatus=<31>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<30>
dwInternetStatus=<30>
dwInternetStatus=<31>
dwInternetStatus=<31>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<30>
dwInternetStatus=<30>
dwInternetStatus=<31>
dwInternetStatus=<31>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<100>
<INTERNET_STATUS_REQUEST_COMPLETE>
async_complete

InternetReadFileEx
GetLastError(InternetReadFileEx)=12018
Ed Debrot
2006-03-31 20:58:32 UTC
Permalink
Silly me... I spent about 2 days trying to resolve this and was able to
accomplish what I wanted by implementing a multi-thread-synchonized transfer
approach inside of 30 minutes. Sometimes (most often) the simple solutions
are the best. Thanks to the asynchronous threads earlier in this newsgroup
for making me think of this simpler solution - workaround - whatever you
want to call it.
Post by Ed Debrot
I've had a wininet program performing for years running FTP but have
recently had a need to modify this to allow for asynchronous FTP. Extracts
of my code are shown below (stripped so don't worry about syntax). It all
works up until I call InternetReadFileEx(). This function returns FALSE and
GetLastError indicates 12018 which says that somehow that operation is
invalid on the handle I am using. I've checked this code over many times and
compared it to similar code I've researched on the internet, but I still
have the problem. I'm running this with Visual Studio 6 and plan on porting
to WinCE when I get it working in Win32. Any help would be greatly
appreciated. Just to be sure, all of my handles up until the
InternetReadFileEx() are valid (I'm using the callback to assign handles and
waiting for request completion before continuing) and if I switch
InternetReadFileEx() with InternetReadFile() it all works fine - but
InternetReadFile() does not run asynchonously. I've included a log of all
callbacks at the bottom.
thanks...
<<<<< CODE >>>>>
h_iopen = InternetOpen(agent_nam,
INTERNET_OPEN_TYPE_DIRECT,
NULL,
NULL,
INTERNET_FLAG_ASYNC);
rc = InternetSetStatusCallback(h_iopen, InternetCallback);
h_iconnect = InternetConnect(h_iopen,
ftp_addr,
INTERNET_INVALID_PORT_NUMBER,
user,
psswd,
INTERNET_SERVICE_FTP,
INTERNET_FLAG_PASSIVE,
myContext);
h_file_remote = my_FtpOpenFile(h_iconnect,
ufnam_remote,
GENERIC_READ,
FTP_TRANSFER_TYPE_ASCII
| INTERNET_FLAG_RELOAD
| INTERNET_FLAG_NO_CACHE_WRITE,
myContext;
{
INTERNET_BUFFERS ib;
memset(&ib, 0, sizeof(INTERNET_BUFFERS));
ib.dwStructSize = sizeof(INTERNET_BUFFERS);
ib.lpvBuffer = lpBuffer;
ib.dwBufferLength = dwNumberOfBytesToRead;
async_reset("InternetReadFileEx");
bVal = InternetReadFileEx(h_file_remote,
&ib,
IRF_ASYNC,
myContext);
}
bVal is returned as FALSE here,
checking getLastError() indicates error code 12018
FtpGetFile(h_iconnect,
fnam_remote,
fnam_local,
full_fnam_local,
FALSE,
0,
FTP_TRANSFER_TYPE_ASCII
| INTERNET_FLAG_RELOAD
| INTERNET_FLAG_NO_CACHE_WRITE,
myContext,
&num_bytes);
<<<<< LOG DATA >>>>>
InternetSetStatusCallback()=ok
InternetConnect
dwInternetStatus=<60>
<INTERNET_STATUS_HANDLE_CREATED>
dwInternetStatus=<10>
dwInternetStatus=<10>
dwInternetStatus=<11>
dwInternetStatus=<11>
dwInternetStatus=<20>
dwInternetStatus=<20>
dwInternetStatus=<21>
dwInternetStatus=<21>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<30>
dwInternetStatus=<30>
dwInternetStatus=<31>
dwInternetStatus=<31>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<30>
dwInternetStatus=<30>
dwInternetStatus=<31>
dwInternetStatus=<31>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<100>
<INTERNET_STATUS_REQUEST_COMPLETE>
async_complete
FtpSetCurrentDirectory
dwInternetStatus=<30>
dwInternetStatus=<30>
dwInternetStatus=<31>
dwInternetStatus=<31>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<100>
<INTERNET_STATUS_REQUEST_COMPLETE>
async_complete
FtpOpenFile
dwInternetStatus=<60>
<INTERNET_STATUS_HANDLE_CREATED>
dwInternetStatus=<30>
dwInternetStatus=<30>
dwInternetStatus=<31>
dwInternetStatus=<31>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<30>
dwInternetStatus=<30>
dwInternetStatus=<31>
dwInternetStatus=<31>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<30>
dwInternetStatus=<30>
dwInternetStatus=<31>
dwInternetStatus=<31>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<30>
dwInternetStatus=<30>
dwInternetStatus=<31>
dwInternetStatus=<31>
dwInternetStatus=<40>
dwInternetStatus=<40>
dwInternetStatus=<41>
dwInternetStatus=<41>
dwInternetStatus=<100>
<INTERNET_STATUS_REQUEST_COMPLETE>
async_complete
InternetReadFileEx
GetLastError(InternetReadFileEx)=12018
Loading...