Archived

This topic is now archived and is closed to further replies.

WinInet problems

This topic is 5651 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all! Im having some problems with the WinInet MFC classes.
    
CInternetSession *session;
session = new CInternetSession();

CFtpConnection *connection = NULL;

connection = session->GetFtpConnection("ftp://hem.passagen.se/jackrabbit","********","*******")


delete session;
  
All i wanted to do here is simply connect to the ftp server. But when i run the program i get an assert message and have shutdown the app. I got my info from msdn if that helps. Anyone know what im doing wrong ? PS: I put the stars there because i didnt want to give out my login and password to my account. [edited by - JackRabbit on June 25, 2002 12:04:38 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
First, error check session, see if it is NULL.

Share this post


Link to post
Share on other sites
Just so you know...

The address, login and password im using works.
I tried it with an FTP client program, and it worked fine.

PS:
Ive been tracing through the calls that happens when i call the GetFtpConnection() method, and the problem happens inside the CFtpConnection class constructor. The contructor makes a call to the InternetConnect function, which returns a HINTERNET handle. The handle returned is NULL so the contructor throws and exception.

Anyone have any idea why this happens ?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Accoding to msdn, the function :

CFtpConnection* GetFtpConnection(
LPCTSTR pstrServer,
LPCTSTR pstrUserName = NULL,
LPCTSTR pstrPassword = NULL,
INTERNET_PORT nPort = INTERNET_INVALID_PORT_NUMBER,
BOOL bPassive = FALSE
);

takes several paramters which if undefeined, defaults to invalid states, which will not allow you to connect to a FTP server. Specificly in this case the port defualts to an invalid port number, instead of the normal port 21 for ftp I beleive.

I dont know about the passive flag though, that must be a windows specific thing.

Good Luck!

-ddn

Share this post


Link to post
Share on other sites
Hi!

I did what you said and set the port number to 21, but it still doesnt work. When tracing through the call i noticed that a CInternetException object gets thrown, so i add a try/catch statment to see if i could get some more info from that:


        

CInternetSession *session = NULL;
CFtpConnection *connection = NULL;

try
{
session = new CInternetSession();

if(session == NULL)
{
AfxMessageBox("Error creating session.");
return FALSE;
}

connection = session->GetFtpConnection("ftp.passagen.se/jackrabbit","******","********",21);
if(connection == NULL)
return false;
}
catch(CInternetException *pExcept)
{
AfxMessageBox(pExcept->ReportError());
}


In the message i get from the pExcept->ReportError() call, it says that the server or address is unknown. I dont understand this because i have test the address and login/pwd with a shareware FTP client i downloaded, and it works just fine.

Any idea on what to do about this ?

PS:

Im using Windows XP, if that has anything to do with it.

Thanks for your reply!

EDIT:
You may be looking at the address and saying "hey, your not using the same address as in your original post!", well thats because that one was incorrect. However it still didnt work after i corrected it. Also, is it important to include the "ftp://" before the address ? I tried both ways, but it didnt work either way.


[edited by - JackRabbit on June 27, 2002 2:06:51 AM]

[edited by - JackRabbit on June 27, 2002 2:07:40 AM]

[edited by - JackRabbit on June 27, 2002 2:08:20 AM]

Share this post


Link to post
Share on other sites
LOL!

How embarresing(how to spell??) is this !?? :D

Solved the problem, guess what, im NOT supposed to include my account directory in the server address!

Sorry for wasting your time with my stupidity.

/me Slaps himself around with a large trout.

Share this post


Link to post
Share on other sites