Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I specify port for InternetConnect 1

Status
Not open for further replies.

cfsjohn

Programmer
Sep 1, 2016
64
US
InternetOpen returns a handle. It is in m.hInternet. lchost contains the ip. lcuserid contains my userid. lcpw contains my password.
Can I tell InternetConnect to use port number 24160 by simply passing that value like: hConnection = InternetConnect(m.hInternet, lchost,24160,lcuserid, lcpw, 1, 0x08000000, 0)
I have tried this and hconnection is always 0
Thanks,
John
 
InternetOpen returns a handle. It is in m.hInternet. lchost contains the ip. lcuserid contains my userid. lcpw contains my password.
Can I tell InternetConnect to use port number 24160 by simply passing that value like: hConnection = InternetConnect(m.hInternet, lchost,24160,lcuserid, lcpw, 1, 0x08000000, 0)
I have tried this and hconnection is always 0
Thanks,
John
Simply add ":24160" to lchost
 
Tried that. It still returns 0.
I tried it with the port number (parameter 3) set to 0 and with it being set to 24160.
Neither worked,
John
 
Have you even read documnetation?

What DECLARE did you use and where did you get it from?

There is no parameter for an internet URL in the call. What you could specify is a proxy server, if at all.
 
Chris, I am not using InternetOpenA. I have never used that command. The command that I am using is InternetOpen and that is working just fine.

I have been using the code I posted in my original post for at least 10 years. It works flawlessly. The only thing different is that I have never had to use a port other than the default port (21). For this project, the vendor wants me to use port 24160 rather than the default port of 21.

The documentation for InternetConnect tells me that the 3rd paramater is about the port. The documentation is extremely confusing but what isn't. My call that I have been using forever has a value of 0 in this parameter. I assume 0 means use the default port 21. It must mean that. It has always worked. So, my original question was can I simply change the 3rd parameter value from 0 to 24160? Of course I had tried that and it was not working.

While looking for an answer, my program was left running and somehow magically using 24160 as the 3rd parameter began working. I suspect the vendor (the owner of the ftp site) fixed something and did not tell me. I had informed the vendor I was having issues connecting.

To make this story even longer, I found a different solution. I switched to using SFTP. I have a chilkat library that let's me do that. SFTP is more secure anyway. Problem solved.

Thanks,
John
 
InternetOpenA is the same as InternetOpen, InternetOpen exists in a Unicode version InternetOpenW or an ANSI version InternetOpenA, if you declare InternetOpen you actually declare InternetOpenA automatically.

InternetOpn is also no VFP function, it is a Windows API function you need to declare. Or - if you defined a user defined FUNCTION or PROCEDURE, then the only way we could find out what goes wrong in such a self defined function is if you post the code definition of that.

So what is your DECLARE or your InternetOpen function and where did you get it from? Still the same question, in principle.

Edit: I realised you switched to ya chilkat component, problem solved. It's still remains a good habit to post your function declare or definition, if you have a question about something that's not native to VFP itself.
 
Last edited:
Here is my method used to do what we are talking about. The CASE tctransfer_acct_vendor_name=="IFS" is the particular code we are talking about:

Code:
LPARAMETERS tcfiletoupload,tcftp_edv_host,tcftp_edv_userid,tcftp_edv_pw,tctransfer_acct_vendor_name

LOCAL lcfiletouploadnopath,llretval,llsuccess

&& This does an upload

lcfiletouploadnopath=JUSTFNAME(tcfiletoupload)

DECLARE INTEGER InternetOpen IN wininet;
    STRING sAgent, INTEGER lAccessType,;
    STRING sProxyName, STRING sProxyBypass,;
    INTEGER lFlags
DECLARE INTEGER InternetCloseHandle IN wininet;
    INTEGER hInet
DECLARE INTEGER InternetConnect IN wininet;
    INTEGER hInternetSession,;
    STRING  sServerName,;
    INTEGER nServerPort,;
    STRING  sUsername,;
    STRING  sPassword,;
    INTEGER lService,;
    INTEGER lFlags,;
    INTEGER lContext
DECLARE INTEGER FtpPutFile IN wininet;
    INTEGER hConnect,;
    STRING  lpszLocalFile,;
    STRING  lpszNewRemoteFile,;
    INTEGER dwFlags,;
    INTEGER dwContext

hInternet = InternetOpen("ITFFtp", 1, 0,0,0)

&& 02/15/2017 - adding code to ensure got a connection
IF ISNULL(m.hInternet) OR m.hInternet = 0
   &&llretval= InternetCloseHandle(m.hInternet)
   CLEAR DLLS "InternetOpen"
   CLEAR DLLS "InternetConnect"
   CLEAR DLLS "FtpPutFile"
   CLEAR DLLS "InternetCloseHandle"
   RELEASE hInternet
   RETURN .f.
ENDIF

DO CASE
   CASE tctransfer_acct_vendor_name=="TOUCHPAY"
    hConnection = InternetConnect(m.hInternet, tcftp_edv_host,;
    0,;
    tcftp_edv_userid, tcftp_edv_pw, 1, 0x08000000, 0)
    lcfiletouploadnopath="./inmates/"+ALLTRIM(lcfiletouploadnopath)
   CASE tctransfer_acct_vendor_name=="IFS"
    hConnection = InternetConnect(m.hInternet, tcftp_edv_host,;
    24160,;
    tcftp_edv_userid, tcftp_edv_pw, 1, 0x08000000, 0)
    lcfiletouploadnopath="./Riverbend/Inbox/"+ALLTRIM(lcfiletouploadnopath)
   CASE tctransfer_acct_vendor_name=="JPAY"
    hConnection = InternetConnect(m.hInternet, tcftp_edv_host,;
    0,;
    tcftp_edv_userid, tcftp_edv_pw, 1, 0x08000000, 0)
ENDCASE

&& 02/15/2017 - adding code to ensure got a connection
IF ISNULL(m.hConnection) OR m.hConnection = 0
   llretval= InternetCloseHandle(m.hInternet)
   &&llretval= InternetCloseHandle(m.hConnection)
   CLEAR DLLS "InternetOpen"
   CLEAR DLLS "InternetConnect"
   CLEAR DLLS "FtpPutFile"
   CLEAR DLLS "InternetCloseHandle"
   RELEASE hInternet
   RELEASE hConnection
   RETURN .f.
ENDIF

IF FtpPutFile(m.hConnection, tcfiletoupload, lcfiletouploadnopath,;
    1, 0) = 0
    llsuccess=.f.
ELSE
    llsuccess=.t.
ENDIF

llretval= InternetCloseHandle(m.hConnection)
llretval= InternetCloseHandle(m.hInternet)
CLEAR DLLS "InternetOpen"
CLEAR DLLS "InternetConnect"
CLEAR DLLS "FtpPutFile"
CLEAR DLLS "InternetCloseHandle"

RELEASE hInternet
RELEASE hConnection
RETURN llsuccess
 
Your thread title speaks of InterentConnect, not InternetOpen, your first sentence still was "InternetOpen returns a handle". That was what tripped me over, as you talked of a handle being 0.

Anyway, you then said you do InternetConnect regarding your port problem. Okay, I misinterpreted that as you meaning InternetOpen all the way, you were already after the InternetOpen phase using InternetConnect, which also returns a handle, that time not the genearl WinInet handle but a connection handle for an FTP server, for example. Fine.

Code:
DECLARE INTEGER InternetConnect IN wininet;
    INTEGER hInternetSession,;
    STRING  sServerName,;
    INTEGER nServerPort,;
    STRING  sUsername,;
    STRING  sPassword,;
    INTEGER lService,;
    INTEGER lFlags,;
    INTEGER lContext
  
*HINTERNET InternetConnectA(
*  [in] HINTERNET     hInternet,
*  [in] LPCSTR        lpszServerName,
*  [in] INTERNET_PORT nServerPort,
*  [in] LPCSTR        lpszUserName,
*  [in] LPCSTR        lpszPassword,
*  [in] DWORD         dwService,
*  [in] DWORD         dwFlags,
*  [in] DWORD_PTR     dwContext
*);

The declare is good, the port number simply is a parameter. You could have defeind and called GetLastError() to find out the resopn you got 0 although you had the right parameterization. If the remote FTP server only allowes SFTP, then WiniInet is insufficient, as it only supports FTP, neither FTPS nor SFTP. It's not just a matter of using a port typically used for SSL connections like 989/990 instead of 21 that makes it secure. If a host changes just that in their configuration of an FTP server, that can be enough, but they might not be aware they actually change the protocol indirectly that way.
 
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top