Click to See Complete Forum and Search --> : FTP Connection Problem


Pasci
October 12th, 2005, 05:34 AM
Hi,
I'm writing a little tool to upload a file to my FTP..

I'm using the following code to connect to the FTP..



//Create a Connection
hOpenHandle = InternetOpen(L"Example",INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

//Connect to Server
hConnection= InternetConnect(hOpenHandle,L"my.ftp.com",
INTERNET_INVALID_PORT_NUMBER,
L"myuser",
L"mypasswd",
INTERNET_SERVICE_FTP,
INTERNET_FLAG_PASSIVE ,0);


if((Error = GetLastError())!=0){
wsprintf( szError, L"Error while connecting to Server!\nErrorCode: %d", Error);
MessageBox( NULL, szError, L"MyUpload", MB_OK );
return -1;
}else{
MessageBox( NULL, L"Connection etablished..", L"MyUpload", MB_OK );
}

if(!FtpPutFile(hConnection, L"\\dir\\file.exe",
L"pub/file.exe", INTERNET_FLAG_TRANSFER_BINARY , 0 )){

wsprintf( szError, L"Error while uploading!\nErrorCode: %d", GetLastError() );
MessageBox( NULL, szError, L"MyUpload", MB_OK );
return( FALSE );
}

MessageBox( NULL, L"Upload succesfull", L"MyUpload", MB_OK );

return 0;




When I my PocketPC is using ActiveSync. the progress is successful, but when i try to us GPRS/EDGE then I always get an error..

55 - The specified network resource or device is no longer available. ERROR_DEV_NOT_EXIST


When I use INTERNET_OPEN_TYPE_PRECONFIG instead of INTERNET_OPEN_TYPE_DIRECT then I always get this error
12029 - ERROR_INTERNET_CANNOT_CONNECT

Any suggestion?

BTw: I'm using WindowsMobile 5.0..

Pasci
October 19th, 2005, 10:55 AM
Solution found..

The error occured cause I called GetLastError() every time without reseting its value..

Solution:
- Call GetLastError() only if hConnection == 0
- Use SetLastError(0)

regards pasci