Discussion:
How can I connect Transfer file to / from FTP Server using vfp 6.0
(too old to reply)
Hughs Man
2003-10-09 09:00:13 UTC
Permalink
To anyone who can help me

How can I use VFP 6.0 to upload or download file from a FTP server using
specified user account
Eric den Doop
2003-10-09 09:13:04 UTC
Permalink
Hello, Hughs!
You wrote on Thu, 9 Oct 2003 17:00:13 +0800:

HM> How can I use VFP 6.0 to upload or download file from a FTP server
HM> using specified user account

Go to the UT at www.universalthread.com and download the FTPCLASS.ZIP file
by Robert Abram.
--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8
Neil Waterworth
2003-10-14 23:05:54 UTC
Permalink
I'd recommend this class, too. Very reliable and easy to use.
Post by Eric den Doop
Hello, Hughs!
HM> How can I use VFP 6.0 to upload or download file from a FTP server
HM> using specified user account
Go to the UT at www.universalthread.com and download the FTPCLASS.ZIP file
by Robert Abram.
--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8
---

Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.525 / Virus Database: 322 - Release Date: 10/10/2003
Demetrios Panayiotakopoulos
2003-10-09 09:57:07 UTC
Permalink
Hi Hughs
A few days ago I was seeking for the same info
Here are the results:

--------------------------------------------------
** 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

*... 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




--------------------------------------------------
**
** Upload files to ftp server
**
#DEFINE GENERIC_READ 2147483648 && &H80000000
#DEFINE GENERIC_WRITE 1073741824 && &H40000000

Local m.ftpServer, m.ftpUserName, m.ftpUserPass

PUBLIC hOpen, hFtpSession
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 sServerName,;
INTEGER nServerPort,;
STRING sUsername,;
STRING sPassword,;
INTEGER lService,;
INTEGER lFlags,;
INTEGER lContext

DECLARE INTEGER FtpOpenFile IN wininet.dll;
INTEGER hFtpSession,;
STRING sFileName,;
INTEGER lAccess,;
INTEGER lFlags,;
INTEGER lContext

DECLARE INTEGER InternetWriteFile IN wininet.dll;
INTEGER hFile,;
STRING @ sBuffer,;
INTEGER lNumBytesToWrite,;
INTEGER @ dwNumberOfBytesWritten

m.ftpServer="klingon"
m.ftpServer="172.10.1.3"
m.ftpUserName="e2userdp"
m.ftpUserPass="e2user"

IF connect2ftp (m.ftpServer, m.ftpUserName, m.ftpUserPass)
lcSourcePath = "C:\" && local folder
lcTargetPath = "/home/e2userdp/" && remote folder (ftp server)

lnFiles = ADIR (arr, lcSourcePath + "lolo.txt")

FOR lnCnt=1 TO lnFiles
lcSource = lcSourcePath + LOWER (arr [lnCnt, 1])
lcTarget = lcTargetPath + LOWER (arr [lnCnt, 1])
? lcSource + " -> " + lcTarget
?? local2ftp (hFtpSession, lcSource, lcTarget)
ENDFOR

= InternetCloseHandle (hFtpSession)
= InternetCloseHandle (hOpen)
ENDIF

FUNCTION connect2ftp (strHost, strUser, strPwd)
** Open the access
hOpen = InternetOpen ("vfp", 1, 0, 0, 0)

IF hOpen = 0
? "No access to WinInet.Dll"
RETURN .F.
ENDIF

** Connect to FTP.
hFtpSession = InternetConnect (hOpen, strHost, 0, strUser, strPwd, 1, 0,
0)

IF hFtpSession = 0
** Close
= InternetCloseHandle (hOpen)
? "FTP " + strHost + " not ready"
RETURN .F.
ELSE
? "Connected to " + strHost + " as: [" + strUser + ", *****]"
ENDIF
RETURN .T.


**--------------------------------------------
** Copying files
**--------------------------------------------
FUNCTION local2ftp (hConnect, lcSource, lcTarget)
** Upload local file to ftp server
hSource = FOPEN (lcSource)
IF (hSource = -1)
RETURN -1
ENDIF

** New file in ftp server
hTarget = FtpOpenFile(hConnect, lcTarget, GENERIC_WRITE, 2, 0)
IF hTarget = 0
= FCLOSE (hSource)
RETURN -2
ENDIF
lnBytesWritten = 0
lnChunkSize = 512 && 128, 512
DO WHILE Not FEOF(hSource)
lcBuffer = FREAD (hSource, lnChunkSize)
lnLength = Len(lcBuffer)
IF lnLength > 0
IF InternetWriteFile (hTarget, @lcBuffer, lnLength, @lnLength) =
1
lnBytesWritten = lnBytesWritten + lnLength
? lnBytesWritten
** Show Progress
ELSE
EXIT
ENDIF
ELSE
EXIT
ENDIF
ENDDO

= InternetCloseHandle (hTarget)
= FCLOSE (hSource)

RETURN lnBytesWritten


Demetrios, Greece
Post by Hughs Man
To anyone who can help me
How can I use VFP 6.0 to upload or download file from a FTP server using
specified user account
PAul Maskens
2003-10-09 12:17:51 UTC
Permalink
I use the classes from Rick Strahl, www.west-wind.com for FTP transfer.
Post by Hughs Man
To anyone who can help me
How can I use VFP 6.0 to upload or download file from a FTP server using
specified user account
Scott Hatmaker
2003-10-09 15:56:30 UTC
Permalink
I have used Rick's stuff as well and it works great. However, none of the
above will do Secure FTP (SFTP) as far as I know which is now a requirement
for us for standard security. The only product that I have found so far to
do SFTP is one from a company called "We Only DO" (www.weonlydo.com). They
create COM and ActiveX components and have examples in VC++ and VB.
Unfortunately, they don't have any for VFP so I started yesterday to try an
figure out how to make the ActiveX control work in VFP. They have a trial
download (called SFTP) which in VB works great.

If someone else makes this work, I would love to see it...
Scott
Post by PAul Maskens
I use the classes from Rick Strahl, www.west-wind.com for FTP transfer.
Post by Hughs Man
To anyone who can help me
How can I use VFP 6.0 to upload or download file from a FTP server using
specified user account
Dan Freeman
2003-10-09 16:37:30 UTC
Permalink
The reason few people support FTPS is because the WinINET API doesn't
support it.

If you post some sample VB code that you're having trouble translating,
someone here will help you out. After all, the mechanics of working with an
ActiveX control are the same in either language: plop it on a form, set a
few properties, call some methods. The syntax may vary, but the basics are
the same.

Dan
Post by Scott Hatmaker
I have used Rick's stuff as well and it works great. However, none of the
above will do Secure FTP (SFTP) as far as I know which is now a requirement
for us for standard security. The only product that I have found so far to
do SFTP is one from a company called "We Only DO" (www.weonlydo.com).
They
Post by Scott Hatmaker
create COM and ActiveX components and have examples in VC++ and VB.
Unfortunately, they don't have any for VFP so I started yesterday to try an
figure out how to make the ActiveX control work in VFP. They have a trial
download (called SFTP) which in VB works great.
If someone else makes this work, I would love to see it...
Scott
Post by PAul Maskens
I use the classes from Rick Strahl, www.west-wind.com for FTP transfer.
Post by Hughs Man
To anyone who can help me
How can I use VFP 6.0 to upload or download file from a FTP server using
specified user account
Scott Hatmaker
2003-10-10 15:30:48 UTC
Permalink
Hi Dan,

I have set a few properties and have the control sending and receiving files
with no errors. I can also get directory listing as well. The only problem
that I am having now is that I can not figure out how to look at the events
that are fired. Specifically, there is a "Done" event that gets fired when
a method or executed command finishes such as a GetFile. I need to be able
to tell when this "Done" event has fired so that I know I can disconnect
safely. Also under the same area, there is a "Progress" that fires multiple
times during the GetFile for instance. It has parameters passed to it that
show the current position (how much of the file has downloaded) and the
total (bytes I think) that should be downloaded. Continually looking at
these in the "Progress" event a person could then write a "Progress" Form or
control to let the user know the status of the download.

I guess I might be missing the fundamentals for checking these events on the
fly after the particular "GetFile" is called. They have the help files
online so you can see how the call takes place and what the events do. It
is at http://www.weonlydo.com/SFTP/Help/ .

I tried to put code inside their "Progress" event that would just pop a Wait
window nowait with the two values so that I could see them. That didn't
work. Let me know what I am not understanding please...

Below are a couple of the Subroutines from the VB example...

Private Sub Sftp_Done(ByVal ErrorCode As Integer, ByVal ErrorText As String)
Dim a As String

a = "DONE with "
If ErrorCode <> 0 Then
a = a & "error " & ErrorCode & " (" & ErrorText & ")"
Else
a = a & "no error"
End If
AddToList a & vbCrLf
Sftp.Disconnect
End Sub

Private Sub Sftp_Progress(ByVal Position As Long, ByVal Total As Long)
AddToList "PROGRESS " & Position & "/" & Total & vbCrLf
End Sub


Thanks for your help...
Scott
Post by Dan Freeman
The reason few people support FTPS is because the WinINET API doesn't
support it.
If you post some sample VB code that you're having trouble translating,
someone here will help you out. After all, the mechanics of working with an
ActiveX control are the same in either language: plop it on a form, set a
few properties, call some methods. The syntax may vary, but the basics are
the same.
Dan
Post by Scott Hatmaker
I have used Rick's stuff as well and it works great. However, none of the
above will do Secure FTP (SFTP) as far as I know which is now a
requirement
Post by Scott Hatmaker
for us for standard security. The only product that I have found so far
to
Post by Scott Hatmaker
do SFTP is one from a company called "We Only DO" (www.weonlydo.com).
They
Post by Scott Hatmaker
create COM and ActiveX components and have examples in VC++ and VB.
Unfortunately, they don't have any for VFP so I started yesterday to try
an
Post by Scott Hatmaker
figure out how to make the ActiveX control work in VFP. They have a trial
download (called SFTP) which in VB works great.
If someone else makes this work, I would love to see it...
Scott
Post by PAul Maskens
I use the classes from Rick Strahl, www.west-wind.com for FTP transfer.
Post by Hughs Man
To anyone who can help me
How can I use VFP 6.0 to upload or download file from a FTP server
using
Post by Scott Hatmaker
Post by PAul Maskens
Post by Hughs Man
specified user account
Andy Rice
2003-10-23 23:25:14 UTC
Permalink
Post by Scott Hatmaker
Hi Dan,
I have set a few properties and have the control sending and receiving files
with no errors. I can also get directory listing as well. The only problem
that I am having now is that I can not figure out how to look at the events
that are fired. Specifically, there is a "Done" event that gets fired when
a method or executed command finishes such as a GetFile. I need to be able
to tell when this "Done" event has fired so that I know I can disconnect
safely. Also under the same area, there is a "Progress" that fires multiple
times during the GetFile for instance. It has parameters passed to it that
show the current position (how much of the file has downloaded) and the
total (bytes I think) that should be downloaded. Continually looking at
these in the "Progress" event a person could then write a "Progress" Form or
control to let the user know the status of the download.
I guess I might be missing the fundamentals for checking these events on the
fly after the particular "GetFile" is called. They have the help files
online so you can see how the call takes place and what the events do. It
is at http://www.weonlydo.com/SFTP/Help/ .
I tried to put code inside their "Progress" event that would just pop a Wait
window nowait with the two values so that I could see them. That didn't
work. Let me know what I am not understanding please...
Below are a couple of the Subroutines from the VB example...
Private Sub Sftp_Done(ByVal ErrorCode As Integer, ByVal ErrorText As String)
Dim a As String
a = "DONE with "
If ErrorCode <> 0 Then
a = a & "error " & ErrorCode & " (" & ErrorText & ")"
Else
a = a & "no error"
End If
AddToList a & vbCrLf
Sftp.Disconnect
End Sub
Private Sub Sftp_Progress(ByVal Position As Long, ByVal Total As Long)
AddToList "PROGRESS " & Position & "/" & Total & vbCrLf
End Sub
Thanks for your help...
Scott
Did you put _VFP.AutoYield = .F. before calling the GetFile()?

Claude Fox
2003-10-10 00:55:44 UTC
Permalink
Check out using the WinInet FTP functions within VFP at:
http://www.news2news.com/vfp/?group=92&=0
Post by Hughs Man
To anyone who can help me
How can I use VFP 6.0 to upload or download file from a FTP server using
specified user account
Loading...