Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Carlos Lima
  Where is Carlos Lima?
 Mindelo
 Cape Verde
 Carlos Lima
 Tags
Subject: Download FTP file Server
Thread ID: 416066 Message ID: 416066 # Views: 54 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Databases, Tables and SQL Server
Date: Saturday, December 20, 2014 10:30:07 AM         
   


I am using the code to try to download a file from a FTP Server but always return "Unable to download selected file"

The code go fine, I see the message WAIT WINDOW 'Transferring ' + lcRemoteFile + ' to ' + lcNewFile + '...' NOWAIT

BUT lnResult return always 0 ZERO. Why? Please Help:


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 = "111.222.333.444"
lcUser = "user"
lcPwd = "password"
lcRemoteFile = "/home/clima/backup-12.18.2014_10-11-06_clima.tar.gz"
lcNewFile = "d:\pensoes\backup-12.18.2014_10-11-06_clima.tar"
lnXFerType = 1 && (default) for ascii, 2 for binary
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

*... The first '0' says use the default port, usually 21.
hftpSession = InternetConnect (hOpen, lcHost,;
0, lcUser, lcPwd, 1, 0, 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

*... 0 to automatically overwrite file
*... 1 to fail if file already exists
fFailIfExists = 0
dwContext = 0 &&... used for callback

WAIT WINDOW 'Transferring ' + lcRemoteFile + ' to ' + lcNewFile + '...' NOWAIT

lnResult = FtpGetFile (hftpSession, lcRemoteFile, lcNewFile, fFailIfExists, 128, lnXFerType, dwContext)

*... 128 = #define FILE_ATTRIBUTE_NORMAL 0x00000080
*... See CreateFile for other attributes

* close handles
= InternetCloseHandle (hftpSession)
= InternetCloseHandle (hOpen)

IF lnResult = 1
*... successful download, do what you want here
WAIT WINDOW 'Completed.' nowait
ELSE
WAIT WINDOW "Unable to download selected file" TIMEOUT 2
ENDIF
RETURN

ENTIRE THREAD

Download FTP file Server Posted by Carlos Lima @ 12/20/2014 10:30:07 AM