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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP cannot open through wininet

Status
Not open for further replies.

ashnam10

Programmer
Jul 18, 2007
24
IN
Hello all,

I am using following code to connect to my ftp site and download the file
But it gives me error : Unable to Connect

Please guide
I am able to open the url in internet explorer but not through program
So here i am missing something

hftpSession always returns 0

Thanks in advance



** FTP_DownLoad
**
** Download files from ftp server
**

PARAMETERS lcHost, lcUser, lcPwd, lcRemoteFile, lcNewFile, lnXFerType

*...........................................................................
*......
*: Usage: DO ftpget WITH ;
*: 'ftp.host', 'name', 'password', 'source.file', 'target.file'[, 1| 2]
*:
*: Where: lcHost = Host computer IP address or name
*: lcUser = user name - anonymous may be used
*: lcPwd = password
*: lcRemoteFile = source file name
*: lcNewFile = target file name
*: lnXFerType = 1 (default) for ascii, 2 for binary
*.................................................................................

*...set up API calls

DECLARE INTEGER InternetOpen IN wininet;
STRING sAgent, INTEGER lAccessType, STRING sProxyName,;
STRING sProxyBypass, STRING lFlags

DECLARE INTEGER InternetCloseHandle IN wininet INTEGER hInet

DECLARE INTEGER InternetConnect IN wininet.DLL;
INTEGER hInternetSession,;
STRING lcHost,;
INTEGER nServerPort,;
STRING lcUser,;
STRING lcPassword,;
INTEGER lService,;
INTEGER lFlags,;
INTEGER lContext

DECLARE INTEGER FtpGetFile IN wininet;
INTEGER hftpSession, ;
STRING lcRemoteFile,;
STRING lcNewFile, ;
INTEGER fFailIfExists,;
INTEGER dwFlagsAndAttributes,;
INTEGER dwFlags, ;
INTEGER dwContext

lcHost = ALLTRIM(lcHost)
lcUser = ALLTRIM(lcUser)
lcPwd = ALLTRIM(lcPwd)
lcRemoteFile = ALLTRIM(lcRemoteFile)
lcNewFile = ALLTRIM(lcNewFile)

sAgent = "vfp"

sProxyName = CHR(0) &&... no proxy
sProxyBypass = CHR(0) &&... nothing to bypass
lFlags = 0 &&... no flags used

*... initialize access to Inet functions
hOpen = InternetOpen (sAgent, 1,;
sProxyName, sProxyBypass, lFlags)

IF hOpen = 0
WAIT WINDOW "Unable to get access to WinInet.Dll" TIMEOUT 2
RETURN
ENDIF
#define IPASSIVE 0x8000000
*... The first '0' says use the default port, usually 21.
hftpSession = InternetConnect (hOpen, lcHost,0, "satvat", "satvat#1234", 1, IPASSIVE, 0) &&... 1 = ftp protocol

IF hftpSession = 0
*... close access to Inet functions and exit
= InternetCloseHandle (hOpen)
WAIT WINDOW "Unable to connect to " + lcHost + '.' TIMEOUT 2
RETURN
ELSE
WAIT WINDOW "Connected to " + lcHost + " as: [" + lcUser + "]" TIMEOUT 1
ENDIF
 
my ftp site" or "a ftp site"?

Try connecting to drivehq.com. Make a free account there and use "ftp.drivehq.com"
If that works (it does here at my place), the problem is not in ftpget.prg but in your ftp server.




 
Hello,

Thanks for trying to help around
but something is amiss in ftpget.prg

because as suggested by you when i give ftp as "ftp.drivehq.com"

I still get the same error message
Please guide me

Thanks in advance
 
He said "make a free account". You have to have an account password for this to work, of course.

Seems you've taken code from faq184-3234 and modified it.

The original code uses parameters, don't change this:

*... The first '0' says use the default port, usually 21.
hftpSession = InternetConnect (hOpen, lcHost,;
0, [highlight #FCE94F]lcUser, lcPwd[/highlight], 1, 0, 0) &&... 1 = ftp protocol

Pass these values in, don't change the source code.

The code as is - ftpget.prg saved as ftpget.prg, called by [tt]DO ftpget WITH 'ftp.host', 'username', 'password', 'server.file', 'localfilename' , 2[/tt] works for me, if it doesn't work for you, you might need to use a different port and/or active mode. But before going into such details, please copy the ftpget.prg as is, name it ftpget.prg and call it as advised in the comment 'Usage'.

Bye, Olaf.



 
Hello,

Yes I did try again by using FTPGet code and it is working with drivehq but still i am not able to get into my ftp site.

Can you suggest some other settings

Where can I set active/passive mode and check?


also will look into Olaf's suggestions and give feedback

Thanks
 
Before you go into changing the code, please try to establish a connection with a normal FTP client, eg FileZilla or Cyyberduck FTP.

If you can easily test whether passive or active mode works there, it may be both work, too. Your code used IPASSIVE constant, the FAQ code has 0 in that place, no flag set, so you already tried active and passive mode. It most probably is something else, case of the password, wrong password to name just two reasons.

Bye, Olaf.
 
Hello,

I did try using CoreFtp and it opens in it
but asks for user id and password i thing that is what we are supplying here also.
So it must be something else.

I did double check username and password but that seems ok

Any more suggestions

Thanks
 
Well, you have to dig deeper into what settings CoreFtp is using. Port numner (21?) active/passive? ascii or binary transfer mode? Even if YOU don't set anything, only give in ftp server name, user and password, CoreFtp is using some settings. And as they work, that's what you want to do with Wininet, too. So you have to find out, that's the whole purpose of trying with the ftp client.

In regard of analysing the VFP code: Debug it step by step, look at result values, if a Windows API function (InternetConnect, FtpGetFile) results in an error, doesen't return the expected value for success, the reason for failure can be looked up via GetLastError, or look into
Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top