Advertisement

WinInet problems

Started by June 25, 2002 11:01 AM
6 comments, last by JackRabbit 22 years, 7 months ago
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]
Emmm,errr....

lol!

why is the last part of my post red ?
sorry about that boys and girls. Hope you can read it!
Advertisement
First, error check session, see if it is NULL.
Hi!

Thanks for the reply.
I checked the session pointer, and it seems ok.

Is there some other method i should call before
the GetFtpConnection() ?

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 ?
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
Advertisement
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]
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.

This topic is closed to new replies.

Advertisement