Steve Meyerson
Programmer
I'm trying to copy a file from my computer to my web host's server using FtpPut.prg (shown below for reference).
The debugger with SET STEP ON shows the connection is made ok but the transfer fails at
My aim is to transfer files in my VFP9 program (exe) as simple (and fast) as possible without additional installation(s) required by the users. Most files will be pdf's (.5-1 MB). I would appreciate any help. TIA.
Steve
The debugger with SET STEP ON shows the connection is made ok but the transfer fails at
Code:
IF FtpPutFile(hftpSession, lcSource,;
lcTarget, lnXFerType, 0) = 1
WAIT WINDOW lcSource + ' transferred.' TIMEOUT 2
ENDIF
My aim is to transfer files in my VFP9 program (exe) as simple (and fast) as possible without additional installation(s) required by the users. Most files will be pdf's (.5-1 MB). I would appreciate any help. TIA.
Steve
Code:
*... FTPPut.PRG ...*
*PARAMETERS lcHost, lcUser, lcPassword, lcSource, lcTarget, lnXFerType
*.................................................................................
*: Usage: DO ftpput 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
*: lcPassword = password
*: lcSource = source file name (remote)
*: lcTarget = target file name (local)
*: lnXFerType = 1 (default) for ascii, 2 for binary
*.................................................................................
set step on
************** My parameters
lcHost = 'gator4247.hostgator.com'
lcUser = 'smeyerson'
lcPassword = 'MyPasswordxxx'
lcSource = 'e:\TextFile.txt'
lcTarget = '/home2/smeyerson/MyFolder'
DECLARE INTEGER InternetOpen IN wininet.DLL;
STRING sAgent,;
INTEGER lAccessType,;
STRING sProxyName,;
STRING sProxyBypass,;
STRING lFlags
DECLARE INTEGER InternetCloseHandle IN wininet.DLL 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 FtpPutFile IN wininet.DLL;
INTEGER hConnect,;
STRING lpszLocalFile,;
STRING lpszNewRemoteFile,;
INTEGER dwFlags,;
INTEGER dwContext
PUBLIC hOpen, hftpSession
lcHost = ALLTRIM(lcHost)
lcUser = ALLTRIM(lcUser)
lcPassword = ALLTRIM(lcPassword)
lcSource = ALLTRIM(lcSource)
lcTarget = ALLTRIM(lcTarget)
lnXFerType = 1
IF connect2ftp (lcHost, lcUser, lcPassword)
WAIT WINDOW 'Transferring....' NOWAIT
IF FtpPutFile(hftpSession, lcSource,;
lcTarget, lnXFerType, 0) = 1
WAIT WINDOW lcSource + ' transferred.' TIMEOUT 2
ENDIF
= InternetCloseHandle (hftpSession)
= InternetCloseHandle (hOpen)
ENDIF
*..................... connect2ftp .........................................
*... Makes sure there is actually a valid connection to the host
FUNCTION connect2ftp (lcHost, lcUser, lcPassword)
* open access to Inet functions
hOpen = InternetOpen ("vfp", 1, 0, 0, 0)
IF hOpen = 0
? "Unable to get access to WinInet.Dll"
RETURN .F.
ENDIF
*... The first '0' says use the default port, usually 21.
hftpSession = InternetConnect (hOpen, lcHost,;
0, lcUser, lcPassword, 1, 0, 0) &&... 1 = ftp protocol
IF hftpSession = 0
* close access to Inet functions and exit
= InternetCloseHandle (hOpen)
? "ftp " + lcHost + " is not available"
RETURN .F.
ELSE
? "Connected to " + lcHost
ENDIF
RETURN .T.
RETURN
*** End of ftpPut.PRG ****************************