PB à toute heure et à tout moment. (à parcourir avec modération)

Le forum (ô combien francophone) des utilisateurs de Powerbuilder.

Recherche rapide

Annonce

Certaines rubriques, dont des cours, sont uniquement visibles par les membres du forum ^^.
Dans la rubrique Liens & Références, vous avez accès à un sommaire de téléchargement, profitez-en !
Il existe maintenant un nouveau TOPIC "Votre CV en Ligne" accessible uniquement par demande.

#1 23-07-2008 21:02:40

frichmout  
Membre Geek
Date d'inscription: 13-12-2006
Messages: 54
Pépites: 260
Banque: 0

[RESOLU] Erreur 4 avec SDK FTP sous PB10.5

J'ai besoin de faire un petit client ftp dans une appli PB.
J'ai téléchargé le SDK trouvé ICI (ftptest.pbl et sockets.pbl)
je suis en PB 10.5. L'appli test a bien migré.
Je l'ai lancé et j'ai tenté la connexion sur un serveur ftp. Je récupère une erreur 4.
Quelqu'un sait-il ce que veut dire l'erreur 4 ?
Quelqu'un a-t-il utlisé ce SDK avec PB10 ?

merci de vos réponses

Dernière modification par frichmout (26-07-2008 12:16:50)

Hors ligne

 

#2 23-07-2008 21:05:47

pick ouic  
La bourse ou la vie ^^
Award: gearotter
Lieu: Massy-Verrières
Date d'inscription: 29-05-2006
Messages: 4659
Pépites: 945
Banque: 2,147,483,647
Site web

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

salut, tu as migré aussi la declaration des fonctions externals ? en mode ansi


Connaitre son ignorance est une grande part de la connaissance.
http://animegifs.free.fr/anime/mazinger/mazinger.gif

Hors ligne

 

#3 24-07-2008 07:57:47

frichmout  
Membre Geek
Date d'inscription: 13-12-2006
Messages: 54
Pépites: 260
Banque: 0

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

j'ai migré la target bestialement. J'imagine que tout à suivi, non ?
tu sais si la liste des codes retour est documentée somewhere ?

Hors ligne

 

#4 24-07-2008 08:06:10

pick ouic  
La bourse ou la vie ^^
Award: gearotter
Lieu: Massy-Verrières
Date d'inscription: 29-05-2006
Messages: 4659
Pépites: 945
Banque: 2,147,483,647
Site web

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

salut,
tu sais qu'à partir de la v10, on passe en unicode ?
donc, le probleme pourrait venir de la.

je fais des recherches de mon coté
A+


Connaitre son ignorance est une grande part de la connaissance.
http://animegifs.free.fr/anime/mazinger/mazinger.gif

Hors ligne

 

#5 24-07-2008 13:30:42

frichmout  
Membre Geek
Date d'inscription: 13-12-2006
Messages: 54
Pépites: 260
Banque: 0

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

qu'à cela ne tienne, testons en PB9 !!
mais en PB9, je ne peux même pas créer la target from existing application. PB ne trouve pas d'objet application dans la ftptest.pbl
Aors, je l'ai accrochée à une target existante. Pas mieux !
Dans le library browser, on ne peut pas ouvrir ces deux pbl pour voir les objets PB qui sont dedans.
Finalement, en version 10, ça marche beaucoup mieux; ça migre, les objets sont modifiables. Il n'y a finalement que la connexion ftp qui merde; un détail, en somme ....

Hors ligne

 

#6 24-07-2008 13:56:01

pick ouic  
La bourse ou la vie ^^
Award: gearotter
Lieu: Massy-Verrières
Date d'inscription: 29-05-2006
Messages: 4659
Pépites: 945
Banque: 2,147,483,647
Site web

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

par exemple :

Code: pb

iu_control.uf_SendData(ib_buffer,LenA(String(ib_buffer)))


cela devient... en pb11

Code: pb

iu_control.uf_SendData(ib_buffer,LenA(String(ib_buffer,EncodingANSI!)))


ect...


Connaitre son ignorance est une grande part de la connaissance.
http://animegifs.free.fr/anime/mazinger/mazinger.gif

Hors ligne

 

#7 24-07-2008 14:56:55

frichmout  
Membre Geek
Date d'inscription: 13-12-2006
Messages: 54
Pépites: 260
Banque: 0

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

là tu m'en bouches un coin ! il faut dire que le pb que j'écris n'utilise jamais ce type de fonctions. Je fais plutôt dans l'appli de gestion.
Je ne me vois pas réécrire toute la pbl pour traquer les différences. Et j'ai pourtant bien besoin de le faire ce mini client ftp.
....

Hors ligne

 

#8 24-07-2008 15:04:41

erasorz  
Admin
Lieu: Babylone
Date d'inscription: 23-11-2006
Messages: 5121
Pépites: 97,197
Banque: 2,147,483,647

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

j'utilise l'objet n_wininet qui s'appuye sur wininet.dll et cela fonctionne bien en PB10.5 et PB11

Code: pb

forward
global type n_wininet from nonvisualobject
end type
type filetime from structure within n_wininet
end type
type win32_find_data from structure within n_wininet
end type
type systemtime from structure within n_wininet
end type
end forward

type filetime from structure
  unsignedlong    dwlowdatetime
  unsignedlong    dwhighdatetime
end type

type win32_find_data from structure
  unsignedlong    dwfileattributes
  filetime    ftcreationtime
  filetime    ftlastaccesstime
  filetime    ftlastwritetime
  unsignedlong    nfilesizehigh
  unsignedlong    nfilesizelow
  unsignedlong    dwreserved0
  unsignedlong    dwreserved1
  character    cfilename[260]
  character    calternatefilename[14]
end type

type systemtime from structure
  unsignedinteger    wyear
  unsignedinteger    wmonth
  unsignedinteger    wdayofweek
  unsignedinteger    wday
  unsignedinteger    whour
  unsignedinteger    wminute
  unsignedinteger    wsecond
  unsignedinteger    wmilliseconds
end type

global type n_wininet from nonvisualobject autoinstantiate
event ue_internetopen ( )
end type

type prototypes
// Windows Functions
Function boolean FileTimeToSystemTime ( &
  FILETIME lpFileTime, &
  Ref SYSTEMTIME lpSystemTime &
  ) Library "kernel32.dll"

Function ulong GetLastError ( &
  ) Library "kernel32.dll"

Function ulong CreateFile ( &
  string lpFileName, &
  ulong dwDesiredAccess, &
  ulong dwShareMode, &
  ulong lpSecurityAttributes, &
  ulong dwCreationDisposition, &
  ulong dwFlagsAndAttributes, &
  ulong hTemplateFile &
  ) Library "kernel32.dll" Alias For "CreateFileW"

Function boolean CloseHandle ( &
  ulong hObject &
  ) Library "kernel32.dll"

Function boolean ReadFile ( &
  ulong hFile, &
  Ref blob lpBuffer, &
  ulong nNumberOfBytesToRead, &
  Ref ulong lpNumberOfBytesRead, &
  ulong lpOverlapped &
  ) Library "kernel32.dll"

// Internet Functions
Function boolean FtpCommand ( &
  ulong hConnect, &
  boolean fExpectResponse, &
  ulong dwFlags, &
  string lpszCommand, &
  ulong dwContext, &
  ref ulong phFtpCommand &
  ) Library "wininet.dll" Alias For "FtpCommandW"

Function boolean FtpCreateDirectory ( &
  ulong hConnect, &
  string lpszDirectory &
  ) Library "wininet.dll" Alias For "FtpCreateDirectoryW"

Function boolean FtpDeleteFile ( &
  ulong hConnect, &
  string lpszFileName &
  ) Library "wininet.dll" Alias For "FtpDeleteFileW"

Function ulong FtpFindFirstFile ( &
  ulong hConnect, &
  string lpszSearchFile, &
  Ref WIN32_FIND_DATA lpFindFileData, &
  ulong dwFlags, &
  ulong dwContext &
  ) Library "wininet.dll" Alias For "FtpFindFirstFileW"

Function boolean FtpGetCurrentDirectory ( &
  ulong hConnect, &
  Ref string lpszCurrentDirectory, &
  Ref ulong lpdwCurrentDirectory &
  ) Library "wininet.dll" Alias For "FtpGetCurrentDirectoryW"

Function boolean FtpGetFile ( &
  ulong hConnect, &
  string lpszRemoteFile, &
  string lpszNewFile, &
  boolean fFailIfExists, &
  ulong dwFlagsAndAttributes, &
  ulong dwFlags, &
  ulong dwContext &
  ) Library "wininet.dll" Alias For "FtpGetFileW"

Function ulong FtpGetFileSize ( &
  ulong hFile, &
  Ref ulong lpdwFileSizeHigh &
  ) Library "wininet.dll" Alias For "FtpGetFileSize"

Function ulong FtpOpenFile ( &
  ulong hConnect, &
  string lpszFileName, &
  ulong dwAccess, &
  ulong dwFlags, &
  ulong dwContext &
  ) Library "wininet.dll" Alias For "FtpOpenFileW"

Function boolean FtpPutFile ( &
  ulong hConnect, &
  string lpszLocalFile, &
  string lpszNewRemoteFile, &
  ulong dwFlags, &
  ulong dwContext &
  ) Library "wininet.dll" Alias For "FtpPutFileW"

Function boolean FtpRemoveDirectory ( &
  ulong hConnect, &
  string lpszDirectory &
  ) Library "wininet.dll" Alias For "FtpRemoveDirectoryW"

Function boolean FtpRenameFile ( &
  ulong hConnect, &
  string lpszExisting, &
  string lpszNew &
  ) Library "wininet.dll" Alias For "FtpRenameFileW"

Function boolean FtpSetCurrentDirectory ( &
  ulong hConnect, &
  string lpszDirectory &
  ) Library "wininet.dll" Alias For "FtpSetCurrentDirectoryW"

Function boolean InternetCloseHandle ( &
  ulong hInternet &
  ) Library "wininet.dll"

Function ulong InternetConnect ( &
  ulong hInternet, &
  string lpszServerName, &
  uint nServerPort, &
  string lpszUserName, &
  string lpszPassword, &
  ulong dwService, &
  ulong dwFlags, &
  ulong dwContext &
  ) Library "wininet.dll" Alias For "InternetConnectW"

Function boolean InternetFindNextFile ( &
  ulong hFind, &
  Ref WIN32_FIND_DATA lpvFindData &
  ) Library "wininet.dll" Alias For "InternetFindNextFileW"

Function boolean InternetGetLastResponseInfo ( &
  Ref ulong lpdwError, &
  Ref string lpszBuffer, &
  Ref ulong lpdwBufferLength &
  ) Library "wininet.dll" Alias For "InternetGetLastResponseInfoW"

Function ulong InternetOpen ( &
  string lpszAgent, &
  ulong dwAccessType, &
  string lpszProxy, &
  string lpszProxyBypass, &
  ulong dwFlags &
  ) Library "wininet.dll" Alias For "InternetOpenW"

Function boolean InternetReadFile ( &
  ulong hFile, &
  ref blob lpBuffer, &
  ulong dwNumberOfBytesToRead, &
  ref ulong lpdwNumberOfBytesRead &
  ) Library "wininet.dll" Alias For "InternetReadFile"

Function boolean InternetWriteFile ( &
  ulong hFile, &
  blob lpBuffer, &
  ulong dwNumberOfBytesToWrite, &
  ref ulong lpdwNumberOfBytesWritten &
  ) Library "wininet.dll" Alias For "InternetWriteFile"

end prototypes

type variables
// Internet handles
ulong iul_internet
ulong iul_session

// Internet open types
CONSTANT uint INTERNET_OPEN_TYPE_PRECONFIG              = 0
CONSTANT uint INTERNET_OPEN_TYPE_DIRECT                = 1
CONSTANT uint INTERNET_OPEN_TYPE_PROXY                  = 3
CONSTANT uint INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  = 4

// Internet service types
CONSTANT uint INTERNET_SERVICE_URL    = 0
CONSTANT uint INTERNET_SERVICE_FTP    = 1
CONSTANT uint INTERNET_SERVICE_GOPHER  = 2
CONSTANT uint INTERNET_SERVICE_HTTP    = 3

// Port numbers
CONSTANT uint INTERNET_INVALID_PORT_NUMBER  = 0
CONSTANT uint INTERNET_DEFAULT_FTP_PORT    = 21
CONSTANT uint INTERNET_DEFAULT_GOPHER_PORT  = 70
CONSTANT uint INTERNET_DEFAULT_HTTP_PORT    = 80
CONSTANT uint INTERNET_DEFAULT_HTTPS_PORT    = 443
CONSTANT uint INTERNET_DEFAULT_SOCKS_PORT    = 1080

// FTP transfer flags
CONSTANT uint FTP_TRANSFER_TYPE_ASCII  = 1
CONSTANT uint FTP_TRANSFER_TYPE_BINARY  = 2

// Internet flags
CONSTANT ulong INTERNET_FLAG_RELOAD        = 2147483648
CONSTANT ulong INTERNET_FLAG_NO_CACHE_WRITE  = 67108864
CONSTANT ulong INTERNET_FLAG_RAW_DATA      = 1073741824

// Internet API error returns
CONSTANT uint INTERNET_ERROR_BASE              = 12000
CONSTANT uint ERROR_INTERNET_OUT_OF_HANDLES        = (INTERNET_ERROR_BASE + 1)
CONSTANT uint ERROR_INTERNET_TIMEOUT            = (INTERNET_ERROR_BASE + 2)
CONSTANT uint ERROR_INTERNET_EXTENDED_ERROR        = (INTERNET_ERROR_BASE + 3)
CONSTANT uint ERROR_INTERNET_INTERNAL_ERROR        = (INTERNET_ERROR_BASE + 4)
CONSTANT uint ERROR_INTERNET_INVALID_URL          = (INTERNET_ERROR_BASE + 5)
CONSTANT uint ERROR_INTERNET_UNRECOGNIZED_SCHEME    = (INTERNET_ERROR_BASE + 6)
CONSTANT uint ERROR_INTERNET_NAME_NOT_RESOLVED      = (INTERNET_ERROR_BASE + 7)
CONSTANT uint ERROR_INTERNET_PROTOCOL_NOT_FOUND      = (INTERNET_ERROR_BASE + 8)
CONSTANT uint ERROR_INTERNET_INVALID_OPTION        = (INTERNET_ERROR_BASE + 9)
CONSTANT uint ERROR_INTERNET_BAD_OPTION_LENGTH      = (INTERNET_ERROR_BASE + 10)
CONSTANT uint ERROR_INTERNET_OPTION_NOT_SETTABLE    = (INTERNET_ERROR_BASE + 11)
CONSTANT uint ERROR_INTERNET_SHUTDOWN            = (INTERNET_ERROR_BASE + 12)
CONSTANT uint ERROR_INTERNET_INCORRECT_USER_NAME    = (INTERNET_ERROR_BASE + 13)
CONSTANT uint ERROR_INTERNET_INCORRECT_PASSWORD      = (INTERNET_ERROR_BASE + 14)
CONSTANT uint ERROR_INTERNET_LOGIN_FAILURE        = (INTERNET_ERROR_BASE + 15)
CONSTANT uint ERROR_INTERNET_INVALID_OPERATION      = (INTERNET_ERROR_BASE + 16)
CONSTANT uint ERROR_INTERNET_OPERATION_CANCELLED    = (INTERNET_ERROR_BASE + 17)
CONSTANT uint ERROR_INTERNET_INCORRECT_HANDLE_TYPE    = (INTERNET_ERROR_BASE + 18)
CONSTANT uint ERROR_INTERNET_INCORRECT_HANDLE_STATE  = (INTERNET_ERROR_BASE + 19)
CONSTANT uint ERROR_INTERNET_NOT_PROXY_REQUEST      = (INTERNET_ERROR_BASE + 20)
CONSTANT uint ERROR_INTERNET_REGISTRY_VALUE_NOT_FOUND  = (INTERNET_ERROR_BASE + 21)
CONSTANT uint ERROR_INTERNET_BAD_REGISTRY_PARAMETER  = (INTERNET_ERROR_BASE + 22)
CONSTANT uint ERROR_INTERNET_NO_DIRECT_ACCESS      = (INTERNET_ERROR_BASE + 23)
CONSTANT uint ERROR_INTERNET_NO_CONTEXT          = (INTERNET_ERROR_BASE + 24)
CONSTANT uint ERROR_INTERNET_NO_CALLBACK          = (INTERNET_ERROR_BASE + 25)
CONSTANT uint ERROR_INTERNET_REQUEST_PENDING        = (INTERNET_ERROR_BASE + 26)
CONSTANT uint ERROR_INTERNET_INCORRECT_FORMAT      = (INTERNET_ERROR_BASE + 27)
CONSTANT uint ERROR_INTERNET_ITEM_NOT_FOUND        = (INTERNET_ERROR_BASE + 28)
CONSTANT uint ERROR_INTERNET_CANNOT_CONNECT        = (INTERNET_ERROR_BASE + 29)
CONSTANT uint ERROR_INTERNET_CONNECTION_ABORTED      = (INTERNET_ERROR_BASE + 30)
CONSTANT uint ERROR_INTERNET_CONNECTION_RESET      = (INTERNET_ERROR_BASE + 31)
CONSTANT uint ERROR_INTERNET_FORCE_RETRY          = (INTERNET_ERROR_BASE + 32)
CONSTANT uint ERROR_INTERNET_INVALID_PROXY_REQUEST    = (INTERNET_ERROR_BASE + 33)
CONSTANT uint ERROR_INTERNET_NEED_UI            = (INTERNET_ERROR_BASE + 34)
CONSTANT uint ERROR_INTERNET_HANDLE_EXISTS        = (INTERNET_ERROR_BASE + 36)
CONSTANT uint ERROR_INTERNET_SEC_CERT_DATE_INVALID    = (INTERNET_ERROR_BASE + 37)
CONSTANT uint ERROR_INTERNET_SEC_CERT_CN_INVALID    = (INTERNET_ERROR_BASE + 38)
CONSTANT uint ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR  = (INTERNET_ERROR_BASE + 39)
CONSTANT uint ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR  = (INTERNET_ERROR_BASE + 40)
CONSTANT uint ERROR_INTERNET_MIXED_SECURITY        = (INTERNET_ERROR_BASE + 41)
CONSTANT uint ERROR_INTERNET_CHG_POST_IS_NON_SECURE  = (INTERNET_ERROR_BASE + 42)
CONSTANT uint ERROR_INTERNET_POST_IS_NON_SECURE      = (INTERNET_ERROR_BASE + 43)
CONSTANT uint ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED  = (INTERNET_ERROR_BASE + 44)
CONSTANT uint ERROR_INTERNET_INVALID_CA          = (INTERNET_ERROR_BASE + 45)
CONSTANT uint ERROR_INTERNET_CLIENT_AUTH_NOT_SETUP    = (INTERNET_ERROR_BASE + 46)
CONSTANT uint ERROR_INTERNET_ASYNC_THREAD_FAILED    = (INTERNET_ERROR_BASE + 47)
CONSTANT uint ERROR_INTERNET_REDIRECT_SCHEME_CHANGE  = (INTERNET_ERROR_BASE + 48)
CONSTANT uint ERROR_INTERNET_DIALOG_PENDING        = (INTERNET_ERROR_BASE + 49)
CONSTANT uint ERROR_INTERNET_RETRY_DIALOG          = (INTERNET_ERROR_BASE + 50)
CONSTANT uint ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR  = (INTERNET_ERROR_BASE + 52)
CONSTANT uint ERROR_INTERNET_INSERT_CDROM          = (INTERNET_ERROR_BASE + 53)

// FTP API errors
CONSTANT uint ERROR_FTP_TRANSFER_IN_PROGRESS    = (INTERNET_ERROR_BASE + 110)
CONSTANT uint ERROR_FTP_DROPPED            = (INTERNET_ERROR_BASE + 111)
CONSTANT uint ERROR_FTP_NO_PASSIVE_MODE      = (INTERNET_ERROR_BASE + 112)

// additional Internet API error codes
CONSTANT uint ERROR_INTERNET_SECURITY_CHANNEL_ERROR  = (INTERNET_ERROR_BASE + 157)
CONSTANT uint ERROR_INTERNET_UNABLE_TO_CACHE_FILE    = (INTERNET_ERROR_BASE + 158)
CONSTANT uint ERROR_INTERNET_TCPIP_NOT_INSTALLED    = (INTERNET_ERROR_BASE + 159)
CONSTANT uint ERROR_INTERNET_DISCONNECTED          = (INTERNET_ERROR_BASE + 163)
CONSTANT uint ERROR_INTERNET_SERVER_UNREACHABLE      = (INTERNET_ERROR_BASE + 164)
CONSTANT uint ERROR_INTERNET_PROXY_SERVER_UNREACHABLE  = (INTERNET_ERROR_BASE + 165)
CONSTANT uint ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT    = (INTERNET_ERROR_BASE + 166)
CONSTANT uint ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT  = (INTERNET_ERROR_BASE + 167)
CONSTANT uint ERROR_INTERNET_SEC_INVALID_CERT      = (INTERNET_ERROR_BASE + 169)
CONSTANT uint ERROR_INTERNET_SEC_CERT_REVOKED      = (INTERNET_ERROR_BASE + 170)

end variables

forward prototypes
public function string of_ftp_deletefile (string as_filename)
public function string of_disconnect_session ()
public function datetime of_filedatetimetopb (filetime astr_filetime)
public function string of_ftp_createdirectory (string as_directory)
public function integer of_ftp_directory (ref s_ftpdirlist astr_dirlist[])
public function boolean of_ftp_fileexists (string as_filename)
public function string of_ftp_internetconnect (string as_servername)
public function string of_ftp_internetconnect (string as_servername, string as_userid, string as_password)
public function string of_ftp_putfile (string as_source, string as_target, boolean ab_ascii)
public function string of_ftp_removedirectory (string as_directory)
public function string of_ftp_renamefile (string as_filename, string as_newname)
public function unsignedlong of_getsession ()
public function string of_internetclosehandle (ref unsignedlong aul_handle)
public function string of_internetopen ()
public function string of_getlasterror ()
public function string of_ftp_command (string as_command, ref string as_response)
public function string of_ftp_setcurrentdirectory (string as_directory)
public function string of_ftp_getcurrentdirectory (ref string as_directory)
public function string of_ftp_getfile (string as_source, string as_target, boolean ab_ascii)
public function string of_ftp_readfile (string as_source, string as_target, long al_window, long al_event)
public function string of_ftp_readfile (string as_source, string as_target)
public function string of_ftp_writefile (string as_source, string as_target)
public function string of_ftp_writefile (string as_source, string as_target, long al_window, long al_event)
public function boolean of_ftp_directoryexists (string as_dirname)
public function string of_ftp_readstring (string as_filename, ref string as_content)
public function string of_ftp_writestring (string as_filename, string as_content)
end prototypes

event ue_internetopen();// initialize the internet dll

String ls_result

ls_result = this.of_InternetOpen()
If Len(ls_result) > 0 Then
  MessageBox(this.ClassName(), ls_result, StopSign!)
End If

end event

public function string of_ftp_deletefile (string as_filename);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_DeleteFile
//
// PURPOSE:    This function deletes a file on the FTP server.
//
// ARGUMENTS:  as_directory  - The directory to create
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Integer li_rc
String ls_result

If FtpDeleteFile(iul_session, as_filename) Then
  ls_result = ""
Else
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function string of_disconnect_session ();// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Disconnect_Session
//
// PURPOSE:    This function disconnects the current session.
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

String ls_result

If iul_session > 0 Then
  ls_result = this.of_InternetCloseHandle(iul_session)
End If

Return ls_result

end function

public function datetime of_filedatetimetopb (filetime astr_filetime);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_FileDateTimeToPb
//
// PURPOSE:    This function converts a file datetime to a PB datetime.
//
// ARGUMENTS:  astr_filetime  - filetime structure
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

DateTime    ldt_filedate
SYSTEMTIME  lstr_SystemTime

SetNull(ldt_filedate)

If Not FileTimeToSystemTime(astr_FileTime, lstr_SystemTime) Then
  Return ldt_filedate
End If

// works with all date formats
ldt_filedate = DateTime( Date(lstr_SystemTime.wYear, &
                    lstr_SystemTime.wMonth, &
                    lstr_SystemTime.wDay), &
                 Time(lstr_SystemTime.wHour, &
                    lstr_SystemTime.wMinute, &
                    lstr_SystemTime.wSecond, &
                    lstr_SystemTime.wMilliseconds) )

Return ldt_filedate

end function

public function string of_ftp_createdirectory (string as_directory);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_CreateDirectory
//
// PURPOSE:    This function creates a directory on the FTP server.
//
// ARGUMENTS:  as_directory  - The directory to create
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Integer li_rc
String ls_result

If FtpCreateDirectory(iul_session, as_directory) Then
  ls_result = ""
Else
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function integer of_ftp_directory (ref s_ftpdirlist astr_dirlist[]);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_Directory
//
// PURPOSE:    This function returns a structure containing a list of files
//          and subdirectories on the FTP server.
//
// ARGUMENTS:  astr_dirlist  - By ref structure of files/dirs
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

WIN32_FIND_DATA lstr_FindData
ulong    lul_hFind
String  ls_null, ls_retval
Integer  li_file
Boolean  lb_morefiles = True

SetNull(ls_null)

lul_hFind = FtpFindFirstFile(iul_session, ls_null, lstr_FindData, &
          INTERNET_FLAG_RAW_DATA + &
          INTERNET_FLAG_NO_CACHE_WRITE + &
          INTERNET_FLAG_RELOAD, 0)

DO WHILE lb_morefiles
  li_file = li_file + 1
  // get file name
  astr_dirlist[li_file].s_FileName = String(lstr_FindData.cfilename)
  astr_dirlist[li_file].s_AltFileName = String(lstr_FindData.calternatefilename)
  If Trim(astr_dirlist[li_file].s_AltFileName) = "" Then
    astr_dirlist[li_file].s_AltFileName = astr_dirlist[li_file].s_FileName
  End If
  // get file date/time
  astr_dirlist[li_file].dt_CreationTime = &
    this.of_FileDateTimeToPB(lstr_FindData.ftCreationTime)
  astr_dirlist[li_file].dt_LastAccessTime = &
    this.of_FileDateTimeToPB(lstr_FindData.ftLastAccessTime)
  astr_dirlist[li_file].dt_LastWriteTime = &
    this.of_FileDateTimeToPB(lstr_FindData.ftLastWriteTime)
  // get file size
  astr_dirlist[li_file].db_FileSize = (lstr_FindData.nFileSizeHigh * (2.0 ^ 32)) + &
    lstr_FindData.nFileSizeLow
  // get file attributes
  astr_dirlist[li_file].ul_Attributes = lstr_FindData.dwFileAttributes
  // find next file
  lb_morefiles = InternetFindNextFile(lul_hFind, lstr_FindData)
LOOP

// close out directory handle
InternetCloseHandle(lul_hFind)

Return UpperBound(astr_dirlist[])

end function

public function boolean of_ftp_fileexists (string as_filename);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_FileExists
//
// PURPOSE:    This function searches for a file in the working directory
//          on the FTP server to see if it exists.
//
// ARGUMENTS:  as_filename  - The name of the file
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

WIN32_FIND_DATA lstr_FindData
ulong    lul_hFind
String  ls_result
Boolean  lb_rtn

lul_hFind = FtpFindFirstFile(iul_session, as_filename, lstr_FindData, &
          INTERNET_FLAG_RAW_DATA + &
          INTERNET_FLAG_NO_CACHE_WRITE + &
          INTERNET_FLAG_RELOAD, 0)

If IsNull(lul_hFind) Or lul_hFind = 0 Then
  ls_result = this.of_GetLastError()
  lb_rtn = False
Else
  // If the requested file is the first one - we're done
  If lstr_FindData.cfilename = as_filename Then
    lb_rtn = True
  Else
    lb_rtn =  False
  End If
End If

// close out directory handle
InternetCloseHandle(lul_hFind)

Return lb_rtn

end function

public function string of_ftp_internetconnect (string as_servername);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_InternetConnect
//
// PURPOSE:    This function opens a FTP session.
//
// ARGUMENTS:  as_servername  - The name of the remote server
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

String ls_null, ls_result

SetNull(ls_null)

iul_session = InternetConnect(iul_internet, as_servername, &
            INTERNET_DEFAULT_FTP_PORT, ls_null, ls_null, &
            INTERNET_SERVICE_FTP, 0, 0)

If IsNull(iul_session) Or iul_session = 0 Then
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function string of_ftp_internetconnect (string as_servername, string as_userid, string as_password);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_InternetConnect
//
// PURPOSE:    This function opens a FTP session.
//
// ARGUMENTS:  as_servername  - The name of the remote server
//          as_userid    - The userid to login with
//          as_password    - The password to login with
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

String ls_null, ls_result

SetNull(ls_null)

iul_session = InternetConnect(iul_internet, as_servername, &
            INTERNET_DEFAULT_FTP_PORT, as_userid, as_password, &
            INTERNET_SERVICE_FTP, 0, 0)

If IsNull(iul_session) Or iul_session = 0 Then
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function string of_ftp_putfile (string as_source, string as_target, boolean ab_ascii);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_PutFile
//
// PURPOSE:    This function uploads a local file to the remote server.
//
// ARGUMENTS:  as_source  - The local filename
//          as_target  - The filename on the server
//          ab_ascii    - Use ASCII or Binary transfer
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Integer li_rc
String ls_result
Ulong    lul_mode

If ab_ascii Then
  lul_mode = FTP_TRANSFER_TYPE_ASCII
Else
  lul_mode = FTP_TRANSFER_TYPE_BINARY
End If

If FtpPutFile(iul_session, as_source, as_target, lul_mode, 0) Then
  ls_result = ""
Else
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function string of_ftp_removedirectory (string as_directory);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_RemoveDirectory
//
// PURPOSE:    This function removes a directory from the FTP server.
//
// ARGUMENTS:  as_directory  - The directory to delete
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Integer li_rc
String ls_result

If FtpRemoveDirectory(iul_session, as_directory) Then
  ls_result = ""
Else
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function string of_ftp_renamefile (string as_filename, string as_newname);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_RenameFile
//
// PURPOSE:    This function renames a file on the FTP server.
//
// ARGUMENTS:  as_filename  - The file being renamed
//          as_newname  - The new name for the file
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Integer li_rc
String ls_result

If FtpRenameFile(iul_session, as_newname, as_filename) Then
  ls_result = ""
Else
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function unsignedlong of_getsession ();// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_GetSession
//
// PURPOSE:    This function returns the session handle.
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Return iul_session

end function

public function string of_internetclosehandle (ref unsignedlong aul_handle);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_InternetCloseHandle
//
// PURPOSE:    This function closes a handle.
//
// ARGUMENTS:  aul_handle  - The handle being closed
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

String ls_result

If InternetCloseHandle(aul_handle) Then
  aul_handle = 0
Else
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function string of_internetopen ();// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_InternetOpen
//
// PURPOSE:    This function initializes the internet dll.
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Application la_app
String ls_null, ls_result

SetNull(ls_null)

la_app = GetApplication()

iul_internet = InternetOpen(la_app.AppName, INTERNET_OPEN_TYPE_PRECONFIG, &
            ls_null, ls_null, 0)

If IsNull(iul_internet) Or iul_internet = 0 Then
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function string of_getlasterror ();// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_GetSession
//
// PURPOSE:    This function gets the last error number and
//          returns descriptive error text.
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

String ls_errortext
ULong lul_errorcode, lul_buffSize
Boolean lb_rc
    
lul_errorcode = GetLastError()

CHOOSE CASE lul_errorcode
  CASE ERROR_INTERNET_OUT_OF_HANDLES
    ls_errortext = "No more handles could be generated at this time."
  CASE ERROR_INTERNET_TIMEOUT
    ls_errortext = "The request has timed out."
  CASE ERROR_INTERNET_EXTENDED_ERROR
    // get extended error information
    InternetGetLastResponseInfo(lul_errorcode, ls_errortext, lul_buffSize)
    IF lul_buffSize > 0 THEN
      ls_errortext = Space(lul_buffSize + 1)
      lb_rc = InternetGetLastResponseInfo(lul_errorcode, ls_errortext, lul_buffSize)
      IF lb_rc = False THEN
        ls_errortext = "An extended error was returned from the server. The call " + &
          "to InternetGetLastResponseInfo to retrieve the error text failed."
      END IF
    ELSE
      ls_errortext = "An extended error was returned from the server. The call " + &
        "to InternetGetLastResponseInfo to retrieve the error text failed."
    END IF
  CASE ERROR_INTERNET_INTERNAL_ERROR
    ls_errortext = "An internal error has occurred."
  CASE ERROR_INTERNET_INVALID_URL
    ls_errortext = "The URL is invalid."
  CASE ERROR_INTERNET_UNRECOGNIZED_SCHEME
    ls_errortext = "The URL scheme could not be recognized or is not supported."
  CASE ERROR_INTERNET_NAME_NOT_RESOLVED
    ls_errortext = "The server name could not be resolved."
  CASE ERROR_INTERNET_PROTOCOL_NOT_FOUND
    ls_errortext = "The requested protocol could not be located."
  CASE ERROR_INTERNET_INVALID_OPTION
    ls_errortext = "A request to InternetQueryOption or InternetSetOption specified " + &
        "an invalid option value."
  CASE ERROR_INTERNET_BAD_OPTION_LENGTH
    ls_errortext = "The length of an option supplied to InternetQueryOption or " + &
        "InternetSetOption is incorrect for the type of option specified."
  CASE ERROR_INTERNET_OPTION_NOT_SETTABLE
    ls_errortext = "The request option cannot be set, only queried."
  CASE ERROR_INTERNET_SHUTDOWN
    ls_errortext = "The Win32 Internet function support is being shut down or unloaded."
  CASE ERROR_INTERNET_INCORRECT_USER_NAME
    ls_errortext = "The request to connect and log on to an FTP server could not " + &
        "be completed because the supplied user name is incorrect."
  CASE ERROR_INTERNET_INCORRECT_PASSWORD
    ls_errortext = "The request to connect and log on to an FTP server could not " + &
        "be completed because the supplied password is incorrect."
  CASE ERROR_INTERNET_LOGIN_FAILURE
    ls_errortext = "The request to connect to and log on to an FTP server failed."
  CASE ERROR_INTERNET_INVALID_OPERATION
    ls_errortext = "The requested operation is invalid."
  CASE ERROR_INTERNET_OPERATION_CANCELLED
    ls_errortext = "The operation was canceled, usually because the handle on which " + &
        "the request was operating was closed before the operation completed."
  CASE ERROR_INTERNET_INCORRECT_HANDLE_TYPE
    ls_errortext = "The type of handle supplied is incorrect for this operation."
  CASE ERROR_INTERNET_INCORRECT_HANDLE_STATE
    ls_errortext = "The requested operation cannot be carried out because the " + &
        "handle supplied is not in the correct state."
  CASE ERROR_INTERNET_NOT_PROXY_REQUEST
    ls_errortext = "The request cannot be made via a proxy."
  CASE ERROR_INTERNET_REGISTRY_VALUE_NOT_FOUND
    ls_errortext = "A required registry value could not be located."
  CASE ERROR_INTERNET_BAD_REGISTRY_PARAMETER
    ls_errortext = "A required registry value was located but is an incorrect type " + &
        "or has an invalid value."
  CASE ERROR_INTERNET_NO_DIRECT_ACCESS
    ls_errortext = "Direct network access cannot be made at this time."
  CASE ERROR_INTERNET_NO_CONTEXT
    ls_errortext = "An asynchronous request could not be made because a zero context " + &
        "value was supplied."
  CASE ERROR_INTERNET_NO_CALLBACK
    ls_errortext = "An asynchronous request could not be made because a callback " + &
        "function has not been set."
  CASE ERROR_INTERNET_REQUEST_PENDING
    ls_errortext = "The required operation could not be completed because one or " + &
        "more requests are pending."
  CASE ERROR_INTERNET_INCORRECT_FORMAT
    ls_errortext = "The format of the request is invalid."
  CASE ERROR_INTERNET_ITEM_NOT_FOUND
    ls_errortext = "The requested item could not be located."
  CASE ERROR_INTERNET_CANNOT_CONNECT
    ls_errortext = "The attempt to connect to the server failed."
  CASE ERROR_INTERNET_CONNECTION_ABORTED
    ls_errortext = "The connection with the server has been terminated."
  CASE ERROR_INTERNET_CONNECTION_RESET
    ls_errortext = "The connection with the server has been reset."
  CASE ERROR_INTERNET_FORCE_RETRY
    ls_errortext = "Calls for the Win32 Internet function to redo the request."
  CASE ERROR_INTERNET_INVALID_PROXY_REQUEST 
    ls_errortext = "The request to the proxy was invalid."
  CASE ERROR_INTERNET_HANDLE_EXISTS
    ls_errortext = "The request failed because the handle already exists."
  CASE ERROR_INTERNET_SEC_CERT_DATE_INVALID 
    ls_errortext = "SSL certificate date that was received from the server is bad. " + &
        "The certificate is expired."
  CASE ERROR_INTERNET_SEC_CERT_CN_INVALID 
    ls_errortext = "SSL certificate common name (host name field) is incorrect. " + &
        "for example, if you entered www.server.com and the common name " + &
        "on the certificate says www.different.com."
  CASE ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR 
    ls_errortext = "The application is moving from a non-SSL to an SSL connection " + &
        "because of a redirect."
  CASE ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR 
    ls_errortext = "The application is moving from an SSL to an non-SSL connection " + &
        "because of a redirect."
  CASE ERROR_INTERNET_MIXED_SECURITY
    ls_errortext = "Indicates that the content is not entirely secure. Some of the " + &
        "content being viewed may have come from unsecured servers."
  CASE ERROR_INTERNET_CHG_POST_IS_NON_SECURE 
    ls_errortext = "The application is posting and attempting to change multiple " + &
        "lines of text on a server that is not secure."
  CASE ERROR_INTERNET_POST_IS_NON_SECURE 
    ls_errortext = "The application is posting data to a sever that is not secure."
  CASE ERROR_FTP_TRANSFER_IN_PROGRESS
    ls_errortext = "The requested operation cannot be made on the FTP session " + &
        "handle because an operation is already in progress."
  CASE ERROR_FTP_DROPPED
    ls_errortext = "The FTP operation was not completed because the session was aborted."
  CASE ELSE
    ls_errortext = "An undefined error occurred: " + String(lul_errorcode)
END CHOOSE

Return ls_errortext

end function

public function string of_ftp_command (string as_command, ref string as_response);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_Command
//
// PURPOSE:    This function executes a command on the FTP server.
//
// ARGUMENTS:  as_command  - The command to execute
//          as_response  - Server response string ( by ref )
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Integer li_rc
ULong lul_ftphandle
String ls_result
ULong lul_errorcode, lul_bufSize

If FtpCommand(iul_session, False, FTP_TRANSFER_TYPE_ASCII, &
      as_command, 0, lul_ftphandle) Then
  // get response buffer size
  InternetGetLastResponseInfo(lul_errorcode, as_response, lul_bufSize)
  If lul_bufSize > 0 Then
    // get response
    as_response = Space(lul_bufSize + 1)
    InternetGetLastResponseInfo(lul_errorcode, &
            as_response, lul_bufSize)
  End If
Else
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function string of_ftp_setcurrentdirectory (string as_directory);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.Ftp_SetCurrentDirectory
//
// PURPOSE:    This function changes the current directory on the FTP server.
//
// ARGUMENTS:  as_directory  - the directory to change to
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Integer li_rc
String ls_result

If FtpSetCurrentDirectory(iul_session, as_directory) Then
  ls_result = ""
Else
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function string of_ftp_getcurrentdirectory (ref string as_directory);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_GetCurrentDirectory
//
// PURPOSE:    This function returns the current directory on the FTP server.
//
// ARGUMENTS:  as_directory  - The directory ( by ref )
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Integer li_rc
String ls_result
ULong lul_rc, lul_buflen

lul_buflen = 256

as_directory = Space(lul_buflen)

If FtpGetCurrentDirectory(iul_session, as_directory, lul_buflen) Then
  ls_result = ""
Else
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function string of_ftp_getfile (string as_source, string as_target, boolean ab_ascii);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_GetFile
//
// PURPOSE:    This function retrieves a file from an FTP server and
//          saves it to local filename.
//
// ARGUMENTS:  as_source  - The filename on the server
//          as_target  - The local filename
//          ab_ascii    - Use ASCII or Binary transfer
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Integer li_rc
String ls_result
Ulong    lul_mode

// delete local file if it exists
If FileExists(as_target) Then
  FileDelete(as_target)
End If

// set transfer mode
If ab_ascii Then
  lul_mode = FTP_TRANSFER_TYPE_ASCII
Else
  lul_mode = FTP_TRANSFER_TYPE_BINARY
End If

If FtpGetFile(iul_session, as_source, as_target, FALSE, 0, lul_mode, 0) Then
  ls_result = ""
Else
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function string of_ftp_readfile (string as_source, string as_target, long al_window, long al_event);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_ReadFile
//
// PURPOSE:    This function reads a remote file and writes it locally. If a
//          window handle is passed, a percent done string is sent.
//          The al_event arg is 1023 + the pbm_custom## number.
//
// ARGUMENTS:  as_source  - The local filename
//          as_target  - The filename on the server
//          al_window  - Handle of the window
//          al_event    - Event number
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Constant ULong GENERIC_READ = 2147483648
Integer li_fnum
Boolean lb_rtn, lb_loop
ULong lul_hFile, lul_bytesread, lul_bufsize
ULong lul_sizelow, lul_sizehigh, lul_totalread
String ls_result, ls_response, ls_buffer
Blob lblob_buffer

lul_bufsize = 2048
lb_loop = True

// open the remote file
lul_hFile = FtpOpenFile(iul_session, as_source, &
          GENERIC_READ, FTP_TRANSFER_TYPE_BINARY, 0)
If lul_hFile > 0 Then
  // get the file size
  lul_SizeLow = FtpGetFileSize(lul_hFile, lul_SizeHigh)
  // open the local file
  li_fnum = FileOpen(as_target, StreamMode!, &
            Write!, LockReadWrite!, Replace!)
  do while lb_loop
    lblob_buffer = Blob(Space(lul_bufsize), EncodingAnsi!)
    lb_loop = InternetReadFile(lul_hFile, lblob_buffer, &
              lul_bufsize, lul_bytesread)
    If lul_bytesread = 0 Then
      lb_loop = False
    Else
      If al_window > 0 Then
        lul_totalread += lul_bytesread
        Send(al_window, al_event, lul_totalread, lul_SizeLow)
      End If
      FileWrite(li_fnum, BlobMid(lblob_buffer, 1, lul_bytesread))
    End If
  loop
  InternetCloseHandle(lul_hFile)
  FileClose(li_fnum)
Else
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function string of_ftp_readfile (string as_source, string as_target);// override of of_ftp_ReadFile defaulting window/event
Return of_ftp_ReadFile(as_source, as_target, 0, 0)

end function

public function string of_ftp_writefile (string as_source, string as_target);// override of of_ftp_WriteFile defaulting window/event
Return of_ftp_WriteFile(as_source, as_target, 0, 0)

end function

public function string of_ftp_writefile (string as_source, string as_target, long al_window, long al_event);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_WriteFile
//
// PURPOSE:    This function reads a local file and writes it remotely. If a
//          window handle is passed, a percent done string is sent.
//          The al_event arg is 1023 + the pbm_custom## number.
//
// ARGUMENTS:  as_source  - The local filename
//          as_target  - The filename on the server
//          al_window  - Handle of the window
//          al_event    - Event number
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Constant ULong INVALID_HANDLE_VALUE = -1
Constant ULong GENERIC_READ     = 2147483648
Constant ULong GENERIC_WRITE    = 1073741824
Constant ULong FILE_SHARE_READ  = 1
Constant ULong FILE_SHARE_WRITE = 2
Constant ULong OPEN_EXISTING    = 3
ULong lul_file, lul_bufsize, lul_hFile
ULong lul_totalread, lul_bytesread, lul_byteswritten
Long ll_filesize
Blob lblob_buffer
Boolean lb_loop
String ls_result

lul_bufsize = 2048
lb_loop = True

// open the local file
lul_file = CreateFile(as_source, GENERIC_READ, &
          FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0)
If lul_file > 0 Then
  // get the file size
  ll_filesize = FileLength(as_source)
  // open the remote file
  lul_hFile = FtpOpenFile(iul_session, as_target, &
            GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY, 0)
  do while lb_loop
    lblob_buffer = Blob(Space(lul_bufsize), EncodingAnsi!)
    lb_loop = ReadFile(lul_file, lblob_buffer, &
              lul_bufsize, lul_bytesread, 0)
    If lul_bytesread = 0 Then
      lb_loop = False
    Else
      If al_window > 0 Then
        lul_totalread += lul_bytesread
        Send(al_window, al_event, lul_totalread, ll_filesize)
      End If
      lb_loop = InternetWriteFile(lul_hFile, lblob_buffer, &
                lul_bytesread, lul_byteswritten)
    End If
  loop
  CloseHandle(lul_file)
  InternetCloseHandle(lul_hFile)
Else
  ls_result = "Could not open '" + as_source + "' for read!"
End If

Return ls_result

end function

public function boolean of_ftp_directoryexists (string as_dirname);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_DirectoryExists
//
// PURPOSE:    This function searches for a directory in the working directory
//          on the FTP server to see if it exists.
//
// ARGUMENTS:  as_filename  - The name of the file
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

WIN32_FIND_DATA lstr_FindData
Constant ulong FILE_ATTRIBUTE_DIRECTORY = 16
ulong    lul_hFind
String  ls_result
Boolean  lb_rtn

lul_hFind = FtpFindFirstFile(iul_session, as_dirname, lstr_FindData, &
          INTERNET_FLAG_RAW_DATA + &
          INTERNET_FLAG_NO_CACHE_WRITE + &
          INTERNET_FLAG_RELOAD, 0)

If IsNull(lul_hFind) Or lul_hFind = 0 Then
  ls_result = this.of_GetLastError()
  lb_rtn = False
Else
  // If the requested directory is the first one - we're done
  If lstr_FindData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY Then
    lb_rtn = True
  Else
    lb_rtn =  False
  End If
End If

// close out directory handle
InternetCloseHandle(lul_hFind)

Return lb_rtn

end function

public function string of_ftp_readstring (string as_filename, ref string as_content);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_ReadString
//
// PURPOSE:    This function reads a remote file and returns it to
//          a string variable.
//
// ARGUMENTS:  as_filename  - The remote filename
//          as_content  - File contents ( by ref )
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Constant ULong GENERIC_READ = 2147483648
ULong lul_hFile, lul_bufsize, lul_bytesread
Blob lblob_buffer
String ls_result, ls_content
Boolean lb_loop

as_content = ""
lul_bufsize = 2048
lb_loop = True

// open the remote file
lul_hFile = FtpOpenFile(iul_session, as_filename, &
          GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0)
If lul_hFile > 0 Then
  do while lb_loop
    lblob_buffer = Blob(Space(lul_bufsize), EncodingAnsi!)
    lb_loop = InternetReadFile(lul_hFile, lblob_buffer, &
              lul_bufsize, lul_bytesread)
    If lul_bytesread = 0 Then
      lb_loop = False
    Else
      ls_content += String(BlobMid(lblob_buffer, 1, lul_bytesread), EncodingAnsi!)
    End If
  loop
  InternetCloseHandle(lul_hFile)
  as_content = ls_content
Else
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

public function string of_ftp_writestring (string as_filename, string as_content);// -----------------------------------------------------------------------------
// SCRIPT:     n_wininet.of_Ftp_WriteString
//
// PURPOSE:    This function writes a string to a file on the remote server.
//
// ARGUMENTS:  as_filename - The filename on the server
//          as_content  - The content of the file
//
// DATE        PROG/ID    DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 10/13/2006  RolandS    Initial Coding
// -----------------------------------------------------------------------------

Constant ULong GENERIC_WRITE = 1073741824
String ls_result, ls_buffer
ULong lul_bufsize, lul_hFile, lul_byteswritten
Long ll_pos, ll_max
Blob lblob_buffer
Boolean lb_rtn

lul_bufsize = 2048

// open the remote file
lul_hFile = FtpOpenFile(iul_session, as_filename, &
          GENERIC_WRITE, FTP_TRANSFER_TYPE_ASCII, 0)
If lul_hFile > 0 Then
  ll_max = Len(as_content)
  For ll_pos = 1 To ll_max Step 2048
    ls_buffer = Mid(as_content, ll_pos, lul_bufsize)
    lblob_buffer = Blob(ls_buffer, EncodingAnsi!)
    lb_rtn = InternetWriteFile(lul_hFile, lblob_buffer, &
                Len(lblob_buffer), lul_byteswritten)
    If lb_rtn = False Then Exit
  Next
  InternetCloseHandle(lul_hFile)
Else
  ls_result = this.of_GetLastError()
End If

Return ls_result

end function

on n_wininet.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_wininet.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

event constructor;// initialize the internet dll
this.Post Event ue_internetopen()

end event

event destructor;// close out the internet dll

String ls_result

If iul_session > 0 Then
  ls_result = this.of_InternetCloseHandle(iul_session)
  If Len(ls_result) > 0 Then
    MessageBox(this.ClassName(), ls_result, StopSign!)
  End If
End If

If iul_internet > 0 Then
  ls_result = this.of_InternetCloseHandle(iul_internet)
  If Len(ls_result) > 0 Then
    MessageBox(this.ClassName(), ls_result, StopSign!)
  End If
End If

end event

N'envoyez jamais un humain faire le travail d'un programme.

Hors ligne

 

#9 24-07-2008 20:37:57

frichmout  
Membre Geek
Date d'inscription: 13-12-2006
Messages: 54
Pépites: 260
Banque: 0

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

Merci pour ce code mais sans mode d'emploi, je ne vois pas bien comment l'utiliser. Je le mets dans quel type d'objet ?
un NVO ? ou il y a un moyen de tout importer pour recréer les objets adhoc ?
Bref pour moi, c'est une huitre sans le couteau à huitre....

Hors ligne

 

#10 24-07-2008 21:07:59

JCZ  
Builder Power
Award: bf
Lieu: 75019 paris
Date d'inscription: 21-05-2007
Messages: 1724
Pépites: 496,453,703,213
Banque: 9,223,372,036,854,776,000

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

tu mets le code dans un ficher que tu nommes n_wininet.sru
et tu importes le fichier dans la pbl de ton choix
puis dans le code tu peux utiliser les differentes fonctions (  of_ftp_deletefile ,  of_disconnect_session, of_ftp_createdirectory... ) à ta convenance


Face à l'agression, la puissance de l'intelligence

Hors ligne

 

#11 25-07-2008 07:31:38

erasorz  
Admin
Lieu: Babylone
Date d'inscription: 23-11-2006
Messages: 5121
Pépites: 97,197
Banque: 2,147,483,647

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

exemple simple pour faire un PUT :

of_ftp_InternetConnect
of_Ftp_PutFile
of_Disconnect_Session


N'envoyez jamais un humain faire le travail d'un programme.

Hors ligne

 

#12 25-07-2008 08:33:56

frichmout  
Membre Geek
Date d'inscription: 13-12-2006
Messages: 54
Pépites: 260
Banque: 0

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

OK; c'est bien plus clair. Merci bcp ! je vais tester cela dès que le temps se met au moche (je suis en Bretagne actuellement).
Là, je reviens de pêcher le bar. Parfois, le bar, c'est plus facile que PB ...

Hors ligne

 

#13 25-07-2008 08:45:41

shahin  
Modérateur
Award: bf
Lieu: val de marne
Date d'inscription: 26-09-2006
Messages: 938
Pépites: 8,675,050,269
Banque: 16,218,225,127,617

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

erasorz

Frichmout, tu fais du PB pendant tes vacances ?


never let people work on more than one thing at once.

Hors ligne

 

#14 25-07-2008 08:46:07

thezerg  
Modérateur
Award: calimero
Lieu: Bordeaux
Date d'inscription: 12-09-2006
Messages: 966
Pépites: 22,449
Banque: 154,120,629,477,379,100

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

shahin a écrit:

erasorz

Frichmout, tu fais du PB pendant tes vacances ?

Chacun ses loisirs shahin

Hors ligne

 

#15 25-07-2008 09:01:00

frichmout  
Membre Geek
Date d'inscription: 13-12-2006
Messages: 54
Pépites: 260
Banque: 0

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

Et oui; ça délasse...et puis j'en ai tellement fait pour mon  boulot pendant des années, je peux bien en faire un peu pour un truc perso...
Je fais un outil de maintenance d'un site oueb totalement paramétré en table sql. C'est un site sur un peintre (www.charles-lapicque.fr, allez voir) . Donc, maintenance des tables en PB/mysql (merci à l'hebergeur de laisser l'accès ODBC ouvert sur la base MySql) et copie à la volée en ftp des photos des tableaux et lithographies, dans les réperotires qui vont bien, après les avoir retaillées à la taille standard du site en question.
J'ai pas mal expérimenté la triplette PB/mysql/php en laissant à chacun ce qu'il a à faire. On arrive à des applis vraiment sympas.
Toute la partie frontoffice en php, le backoffice en PB et la base en MySQL.
voilà...
tiens un truc un peu hors sujet : connaissez-vous Codecharge studio 4 ? J'ai eu l'occasion de tester et d'utiliser pour générer des applis php rapidement sur des bases MySQL. c'est assez bluffant.

A+

Hors ligne

 

#16 25-07-2008 20:47:51

frichmout  
Membre Geek
Date d'inscription: 13-12-2006
Messages: 54
Pépites: 260
Banque: 0

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

erazorz, j'ai copié l'ensemble du code par copier-coller dans l'éditeur de PB; sauvegardé le tout dans n_wininet.sru.
J'ai fait l'import dans une pbl vide .
ça s'est bien passé (une fois rajouté un entête correct). Par contre, il a fallu que je mette en commentaire la fonction
public function integer of_ftp_directory (ref s_ftpdirlist astr_dirlist[])
car s_ftpdirlist ne plait pas à PB. Je ne vois pas bien pourquoi mais bon, ça ne va pas m'empècher de faire joujou avec le machin...
Si tu vois pourquoi...

Hors ligne

 

#17 26-07-2008 07:45:58

erasorz  
Admin
Lieu: Babylone
Date d'inscription: 23-11-2006
Messages: 5121
Pépites: 97,197
Banque: 2,147,483,647

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

effectivement tu as besoin de cette structure :

Code: pb

global type s_ftpdirlist from structure
  string    s_filename
  string    s_altfilename
  datetime    dt_creationtime
  datetime    dt_lastaccesstime
  datetime    dt_lastwritetime
  double    db_filesize
  unsignedlong    ul_attributes
end type

N'envoyez jamais un humain faire le travail d'un programme.

Hors ligne

 

#18 26-07-2008 08:25:31

frichmout  
Membre Geek
Date d'inscription: 13-12-2006
Messages: 54
Pépites: 260
Banque: 0

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

Merci bcp. J'ai fait mon premier put hier soir; ça a marché impec !! Je mettrais bien le thread en résolu mais je ne sais pas comment faire.
En tous cas, merci à tous.

Hors ligne

 

#19 26-07-2008 08:49:06

foon  
N2iGeek + MangasGeek = foon
Award: bf
Lieu: Bonchamp-Lès-Laval
Date d'inscription: 28-02-2007
Messages: 2487
Pépites: 88
Banque: 9,223,372,036,854,776,000

Re: [RESOLU] Erreur 4 avec SDK FTP sous PB10.5

Bonjour frichmout,

Il te suffit de modifier le titre du premier message de ce topic en ajoutant [RESOLU] devant.
Bonne pêche au bar


Seuls ceux qui ne font rien ne font jamais d'erreurs
http://www.nerdtests.com/images/badge/163124fb7fb459a3.gif

Hors ligne

 

Pied de page des forums

Propulsé par FluxBB 1.2.22