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

FTPPutFile.prg .. how to log off?

Status
Not open for further replies.

EzLogic

Programmer
Aug 21, 2001
1,230
0
0
US
I am using FTPPut to send an XML file to a zebra printer.
Everything works great, EXCEPT: After the 5th file being sent, the ftp returns that the host not available.
After further investigation, i found out that the Zebra only allows 5 connection.

I tried in in Dos ftp command.. i oppened 5 sessions, and the 6th refused it.

So, how do I ensure that the FTP is closed/logged out?


Code:
&& Code that sends the file to the zebra
FTPPut(lcFTP,'','',lcFile,'Standard.xml',2) 




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

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)

IF connect2ftp (lcHost, lcUser, lcPassword)
   WAIT WINDOW 'Transferring....' NOWAIT
   IF FtpPutFile(hftpSession, lcSource,;
         lcTarget, lnXFerType, 0) = 1
      WAIT WINDOW lcSource + ' transferred.' TIMEOUT 1
   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    
      MESSAGEBOX("Unable to get access to WinInet.Dll",48,'FTP')
      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)    
      MESSAGEBOX("ftp " + lcHost + " is not available",48,'FTP')
      RETURN .F.   
   ENDIF    
RETURN .T.   
RETURN
*** End of ftpPut.PRG *************************************************************


Ez Logic
Michigan
 
There was a catch with wininet.

The connections are not really closed, but cached and pooled for future use. The limitation of connections rather is a limitation of Wininet, if I google the problem I find:
I would try to keep the InternetOpen handle open longer and only close ftp connections. Another thing forcing Wininet to really close handles is informing about setting changes (even if you really don't change any): InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0)

INTERNET_OPTION_SETTINGS_CHANGED is 39

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top