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 vfp file 1

Status
Not open for further replies.

dawg

Programmer
Dec 20, 1999
22
US
I have a project where I need to populate a table with data and then ftp it to a ftp site. Is there any vfp commands that would allow me ftp the table directly from the program used to popuplate the table?

Thanks for any help,

Tim Phillips
 
Here's a little routine I use:
Code:
*... ftpPut.prg ...
PARAMETERS lcHost, lcUser, lcPassword, lcSource, lcTarget

*... Usage: DO ftpput WITH ;
*...       'ftp.host', 'name', 'password', 'source.file', 'target.file'

#DEFINE XFER_ASCII   1
#DEFINE XFER_BINARY  2

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

IF connect2ftp (lcHost, lcUser, lcPassword)
   IF FtpPutFile (hFtpSession, lcSource,;
         lcTarget, XFER_ASCII, 0) = 1
      ?'File transferred.'
   ENDIF

   = InternetCloseHandle (hFtpSession)
   = InternetCloseHandle (hOpen)
ENDIF

FUNCTION  connect2ftp (strHost, strUser, strPwd)
hOpen = InternetOpen ("vfp", 1, 0, 0, 0)
IF hOpen = 0
   ? "Unable to get access to WinInet.Dll"
   RETURN .F.
ENDIF

hFtpSession = InternetConnect (hOpen, strHost, 0,;
   strUser, strPwd, 1, 0, 0)    &&... 1 = ftp

IF hFtpSession = 0
   * close Inet and exit
   = InternetCloseHandle (hOpen)
   ? "FTP " + strHost + " is not available"
   RETURN .F.
ELSE
   ? "Connected to " + strHost
ENDIF
RETURN .T.
Thanks to some help from news2news.com.
Dave S. [cheers]
 
Dave,
I have on error on grup:
IF ftpPutFile (hftpSession, lcSource,;
lcTarget, XFER_ASCII, 0) = 1
?'File transferred.'
ENDIF
the error is
"Can't find entry point in ftpPutFile in the DLL"
Why?
Thank you
Marius
 
Sorry, I used BEAUTIFY on the thing and it converted case on that function call, so it doesn't get recognized in the .DLL. Here's the 'fixed' code.

Change this:
Code:
DECLARE INTEGER
f
Code:
tpPutFile IN wininet.DLL;
   INTEGER hConnect,;
   STRING  lpszLocalFile,;
   STRING  lpszNewRemoteFile,;
   INTEGER dwFlags,;
   INTEGER dwContext

to this:

DECLARE INTEGER
F
Code:
tpPutFile IN wininet.DLL;
   INTEGER hConnect,;
   STRING  lpszLocalFile,;
   STRING  lpszNewRemoteFile,;
   INTEGER dwFlags,;
   INTEGER dwContext


And this:
   IF
f
Code:
tpPutFile (hftpSession, lcSource,;
         lcTarget, XFER_ASCII, 0) = 1
      ?'File transferred.'
   ENDIF

to this:

   IF
F
Code:
tpPutFile (hftpSession, lcSource,;
         lcTarget, XFER_ASCII, 0) = 1
      ?'File transferred.'
   ENDIF

Here's the complete code:

Code:
*... ftpPut.prg ...
PARAMETERS lcHost, lcUser, lcPassword, lcSource, lcTarget

*... Usage: DO ftpput WITH ;
*...       'ftp.host', 'name', 'password', 'source.file', 'target.file'

#DEFINE XFER_ASCII   1
#DEFINE XFER_BINARY  2

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

IF connect2ftp (lcHost, lcUser, lcPassword)
   IF FtpPutFile (hftpSession, lcSource,;
         lcTarget, XFER_ASCII, 0) = 1
      ?'File transferred.'
   ENDIF

   = InternetCloseHandle (hftpSession)
   = InternetCloseHandle (hOpen)
ENDIF

FUNCTION  connect2ftp (strHost, strUser, strPwd)
hOpen = InternetOpen ("vfp", 1, 0, 0, 0)
IF hOpen = 0
   ? "Unable to get access to WinInet.Dll"
   RETURN .F.
ENDIF

hftpSession = InternetConnect (hOpen, strHost, 0,;
   strUser, strPwd, 1, 0, 0)    &&... 1 = ftp

IF hftpSession = 0
   * close Inet and exit
   = InternetCloseHandle (hOpen)
   ? "ftp " + strHost + " is not available"
   RETURN .F.
ELSE
   ? "Connected to " + strHost
ENDIF
RETURN .T.
Dave S. [cheers]
 
machele,

What an idiot I am. I posted the required changes, but didn't make them in the posted code. I apologize profusely. Ignore the 'complete code', and make the changes as I pointed out in red at the beginning of the post. So sorry.
I promise, it works. :)
Dave S. [cheers]
 
Dave, you should write a faq on this!

Thanks for the code! I've been wanting to do this for a while, but haven't taken the time to figure it out...
 
I've thought about it, and now that there has been a desire expressed, why not. I'll do it. It seems this requirement pops up every once in a while.

Stay tuned....
Dave S. [cheers]
 
Okay. I made an FAQ. Go check it out and let me know what you think. Also, download the form and give it a try.

How do I transfer files using FTP?
faq184-3234
Dave S. [cheers]
 
DSummZZZ,
I have the same error using your FAQ.
Thank you
Marius
 
...keep goin' Dave. It happens to the best of us all the time!

Better make that 48x.

Thanx for sharing your knowledge with us!

Regards - Wayne
 
machele & xBaseDude,

Okay, here's the scoop. There's is an issue with tek-tips. I checked, checked again then posted the code. Upon further review, Tek-Tips is converting my code to lower case. It isn't me after all! I even went to edit the faq to convert the lower case-ed function calls, but when I try to edit them, they are already the porper case. I will send a not to tek-tips and see what we can work out. In the meantime, if you manually edit the following function calls to read proper case, they will work! I have put them in quotes so hopefully they won't get converted.

Make these changes:

"ftpGetFile" -> "FtpGetFile"
"ftpPutFile" -> "FtpPutFile"
"ftpDeleteFile" -> "FtpDeleteFile"
Dave S. [cheers]
 
Hello all, (especailly machele & xBaseDude).

There is indeed a problem when posting an faq. Apparently, 'ftp' in code when not surrounded by quotes, gets converted to lowercase. This causes problems when the routine tries to use it. I have made those function calls bold in the faq so they code will work unmodified. Thanks for being patient and re retrying the code.
Dave S. [cheers]
 
Dave;

I don't know if you saw this or not, but if you click on the process TGML link in Step 2 of the Message textbox, it brings up a pop-up that sez...

A small minority of members, posting certain types of programming code, experience conflicts with TGML. If you are posting code, please check your output to be sure it outputs correctly. (Especially check the formatting around URLS and array subscripts). If your code does not look right, try surrounding the programming portion with the
Code:
tags to ignore TGML, or use the checkbox to disallow TGML from your post altogether.


I dunno if the "code" tag will post correctly, but surround your code with....
{code}{/code}
replacing the kudosis? with right and left "[" "]"

HTH - Wayne

sig_jugler.gif
...all this and tap dancing too!
 
xBaseDude

I believe this was a problem brought up to the management about a month ago, I had sent them a e-mail regarding the fact the if you type a url in the message body, Code Fusion for some reason decides to add a semi-colon at the end of it. For example in this I did not put the ";" at the end of it, but Cold Fusion decides to do it (" Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Wayne and Mike,

I used the code/endcode tags like you mentioned.
Tech support also called me and told me that they are not totally sure of all the ramifications of the TGML tags. There is some unpredictability that does happen and suggested a couple work arounds. It's all under control now I believe. I would like to edit the postings in this thread to make them show up correctly though.
Dave S. [cheers]
 
Dave S.

I'm not sure if it can be done, but I would suggest you red-flag the post you want to fix, and in the message explain the situation and see if they can fix it for you.
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top