Page 1 of 1

Ayuda con "C"

Posted: Tue Sep 03, 2013 3:57 pm
by rolando
Buen día,

Estoy intentando usar un par de funciones publicadas en el blog de Biel al efecto de actualizar aplicaciones vía FTP.

Por un lado pasa algo "raro" ya que si bajo un archivo de 2 MB, lo hace sin problemas, pero si pretendo bajar un archivo de 8 MB se bloquea la bajada cuando esta llega al 99% y se bloquea también la aplicación.

La duda está porque al compilar todo, me da un error:

Code: Select all

2006: Suspicious pointer conversion in function HB_FUN_FILETIMES

Copio el código "C" de Biel para ver si alguien me ayuda. Gracias.

Rolando :D

Code: Select all

#pragma BEGINDUMP
#include <Windows.h>
#include <mapiwin.h>
#include <hbApi.h>
                     //nTime 1=Last Update, 2=Last Acces, 3=Creation, defecto last update
HB_FUNC( FILETIMES ) // params cFileName, nTime --> { nYear, nMonth, nDay, nHour, nMin, nSec }
{
   LPSTR cFileName = hb_parc( 1 ) ;
   int nTime       = ( ISNUM( 2 ) ? hb_parni( 2 ) :  1 ) ; // defaults to 1

   FILETIME ftCreate, ftAccess, ftWrite ;
   SYSTEMTIME stTime ;
   BOOL bRet ;
   HANDLE hFile = CreateFile( cFileName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 

FILE_ATTRIBUTE_NORMAL, 0 ) ;

   if( ! hFile )
      return ;

   GetFileTime( (HANDLE) hFile, &ftCreate, &ftAccess, &ftWrite ) ;

   switch( nTime )
   {
      case 1 : // last update
         FileTimeToSystemTime( &ftWrite, &stTime ) ;
         break ;
      case 2 : // last access
         FileTimeToSystemTime( &ftAccess, &stTime ) ;
         break ;
      case 3 : // creation
         FileTimeToSystemTime( &ftCreate, &stTime ) ;
         break ;
      default : // last update
         FileTimeToSystemTime( &ftWrite, &stTime ) ;
         break ;
   }

   SystemTimeToTzSpecificLocalTime( NULL, &stTime, &stTime ) ;
   CloseHandle( hFile ) ;
   hb_reta( 6 ) ;
   hb_storni( stTime.wYear,   -1, 1 ) ;
   hb_storni( stTime.wMonth,  -1, 2 ) ;
   hb_storni( stTime.wDay,    -1, 3 ) ;
   hb_storni( stTime.wHour,   -1, 4 ) ;
   hb_storni( stTime.wMinute, -1, 5 ) ;
   hb_storni( stTime.wSecond, -1, 6 ) ;
}




#define FA_RDONLY           1   /* R */
#define FA_HIDDEN           2   /* H */
#define FA_SYSTEM           4   /* S */
#define FA_LABEL            8   /* V */
#define FA_DIREC           16   /* D */
#define FA_ARCH            32   /* A */
#define FA_NORMAL           0






HB_FUNC(FILESIZE)

   {
   LPCTSTR szFile;
   DWORD dwFlags=FILE_ATTRIBUTE_ARCHIVE;
   HANDLE hFind;
   WIN32_FIND_DATA  hFilesFind;
      int iAttr;
      if (hb_pcount() >=1){
         szFile=hb_parc(1);
         if (ISNUM(2))      {
            iAttr=hb_parnl(2);
         }
         else{
         iAttr=63;
         }
            if( iAttr & FA_RDONLY )
               dwFlags |= FILE_ATTRIBUTE_READONLY;

            if( iAttr & FA_HIDDEN )
               dwFlags |= FILE_ATTRIBUTE_HIDDEN;

            if( iAttr & FA_SYSTEM )
               dwFlags |= FILE_ATTRIBUTE_SYSTEM;
            if( iAttr & FA_NORMAL )
               dwFlags |=    FILE_ATTRIBUTE_NORMAL;

            hFind = FindFirstFile(szFile,&hFilesFind);
                  if (hFind != INVALID_HANDLE_VALUE){
                      if (dwFlags & hFilesFind.dwFileAttributes) {
                         if(hFilesFind.nFileSizeHigh>0)
                              hb_retnl((hFilesFind.nFileSizeHigh*MAXDWORD)+hFilesFind.nFileSizeLow);
                         else
                              hb_retnl(hFilesFind.nFileSizeLow);
                       }
                   else
                           hb_retnl(-1);
                     }

         }
}

#pragma ENDDUMP
...

Re: Ayuda con "C"

Posted: Tue Sep 03, 2013 4:05 pm
by Antonio Mart.
Rolando,

Yo probaria a hacer la operacion con Ftp.exe, con el comando Get de Ftp.exe, para descartar problemas con el programa y fijarse en el transito ftp.
Lo digo porque me da la sensacion que el error de compilacion no tenga nada que ver con el problema que tienes.

Aqui parece que hay una forma de bajar archivos de un ftp usando un archivo bat: http://samuel-granados.com/blog/descarga-ftp-mejorado/

Saludos

Re: Ayuda con "C"

Posted: Tue Sep 03, 2013 7:27 pm
by nnicanor
Hola,

Yo hice los ajustes para poder compilar con BCC, VC2010, MINGW con Harbour y xHarbour

Code: Select all


#pragma BEGINDUMP

#include <Windows.h>
#ifndef __MINGW__
#include <mapiwin.h>  //nmm 12/03/2013
#endif
#include <hbApi.h>
                     //nTime 1=Last Update, 2=Last Acces, 3=Creation, defecto last update
HB_FUNC( FILETIMES ) // params cFileName, nTime --> { nYear, nMonth, nDay, nHour, nMin, nSec }
{
   LPSTR cFileName = ( LPSTR ) hb_parc( 1 ) ;
   #ifdef __XHARBOUR__
      int nTime       = ( ISNUM( 2 ) ? hb_parni( 2 ) :  1 ) ; // defaults to 1
    #else
      int nTime       = ( HB_ISNUM( 2 ) ? hb_parni( 2 ) :  1 ) ; // defaults to 1
   #endif

   FILETIME ftCreate, ftAccess, ftWrite ;
   SYSTEMTIME stTime ;
   #ifndef __XHARBOUR__
    //  HB_BOOL bRet ;
   #else
       BOOL bRet ;
    #endif
   HANDLE hFile = CreateFile( cFileName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ) ;

   if( ! hFile )
      return ;

   GetFileTime( (HANDLE) hFile, &ftCreate, &ftAccess, &ftWrite ) ;

   switch( nTime )
   {
      case 1 : // last update
         FileTimeToSystemTime( &ftWrite, &stTime ) ;
         break ;
      case 2 : // last access
         FileTimeToSystemTime( &ftAccess, &stTime ) ;
         break ;
      case 3 : // creation
         FileTimeToSystemTime( &ftCreate, &stTime ) ;
         break ;
      default : // last update
         FileTimeToSystemTime( &ftWrite, &stTime ) ;
         break ;
   }

   SystemTimeToTzSpecificLocalTime( NULL, &stTime, &stTime ) ;
   CloseHandle( hFile ) ;
   hb_reta( 6 ) ;

    #ifdef __XHARBOUR__
      hb_storni( stTime.wYear,   -1, 1 ) ;
      hb_storni( stTime.wMonth,  -1, 2 ) ;
      hb_storni( stTime.wDay,    -1, 3 ) ;
      hb_storni( stTime.wHour,   -1, 4 ) ;
      hb_storni( stTime.wMinute, -1, 5 ) ;
      hb_storni( stTime.wSecond, -1, 6 ) ;
    #else
      hb_storvni( stTime.wYear,   -1, 1 ) ;
      hb_storvni( stTime.wMonth,  -1, 2 ) ;
      hb_storvni( stTime.wDay,    -1, 3 ) ;
      hb_storvni( stTime.wHour,   -1, 4 ) ;
      hb_storvni( stTime.wMinute, -1, 5 ) ;
      hb_storvni( stTime.wSecond, -1, 6 ) ;
   #endif
}

#define FA_RDONLY           1   /* R */
#define FA_HIDDEN           2   /* H */
#define FA_SYSTEM           4   /* S */
#define FA_LABEL            8   /* V */
#define FA_DIREC           16   /* D */
#define FA_ARCH            32   /* A */
#define FA_NORMAL           0

HB_FUNC(FILESIZE)

   {
   LPCTSTR szFile;
   DWORD dwFlags=FILE_ATTRIBUTE_ARCHIVE;
   HANDLE hFind;
   WIN32_FIND_DATA  hFilesFind;
      int iAttr;
      if (hb_pcount() >=1){
         szFile=hb_parc(1);
         #ifdef __XHARBOUR__
         if (ISNUM(2))      {
         #else
         if (HB_ISNUM(2))      {
            #endif
            iAttr=hb_parnl(2);
         }
         else{
         iAttr=63;
         }
            if( iAttr & FA_RDONLY )
               dwFlags |= FILE_ATTRIBUTE_READONLY;

            if( iAttr & FA_HIDDEN )
               dwFlags |= FILE_ATTRIBUTE_HIDDEN;

            if( iAttr & FA_SYSTEM )
               dwFlags |= FILE_ATTRIBUTE_SYSTEM;
            if( iAttr & FA_NORMAL )
               dwFlags |=    FILE_ATTRIBUTE_NORMAL;

            hFind = FindFirstFile(szFile,&hFilesFind);
                  if (hFind != INVALID_HANDLE_VALUE){
                      if (dwFlags & hFilesFind.dwFileAttributes) {
                         if(hFilesFind.nFileSizeHigh>0)
                              hb_retnl((hFilesFind.nFileSizeHigh*MAXDWORD)+hFilesFind.nFileSizeLow);
                         else
                              hb_retnl(hFilesFind.nFileSizeLow);
                       }
                   else
                           hb_retnl(-1);
                     }

         }
}

#pragma ENDDUMP

 
Slds

Re: Ayuda con "C"

Posted: Wed Sep 04, 2013 1:01 pm
by rolando
Gracias a ambos por responder.

Actualicé las funciones en "C" y quedó OK, no muestra más la advertencia.

Pero el problema persiste. Comento que estoy usando un servidor "casero" en el cual tengo instalado el FIlezilla como servidor FTP y funcionaba correctamente y ahora me doy cuenta que empezó a funcionar mal luego de las últimas actualizaciones del win server 2003 en el que está instalado. Lo raro es que usando el fillezilla cliente, subo y bajo todo tipo de archivos sin ningún tipo de problemas.

Probando con el comando ftp.exe, baja bién los archivos de 2 MB pero, y aunque lo baja todo, se queda "colgado" y no informa que ha sido transferido si bajo un archivo de 8 MB.

Resumiendo: EL problema pareciera estar en el servidor FTP que es "harina de otro costal".

Gracias.

Rolando :D