Page 2 of 2

Re: Subuir un fichero a un servidor

PostPosted: Thu Nov 30, 2023 8:05 am
by miarcod
Victor,

Perdona por el abuso, pero podrías pasarme el código para usar el curl.exe y subir el fichero pdf desde la linea de comandos

Gracias

Re: Subuir un fichero a un servidor

PostPosted: Thu Nov 30, 2023 8:23 am
by VictorCasajuana
miarcod wrote:Victor,

Perdona por el abuso, pero podrías pasarme el código para usar el curl.exe y subir el fichero pdf desde la linea de comandos

Gracias


Jajaj, tranquilo, no es abuso, ni mucho menos.

No obstante, en el primer post de este hilo ya lo pusiste:

Code: Select all  Expand view
curl --location 'https://www.zohoapis.eu/crm/v5/Leads/594992000001640002/Attachments' \
--header 'Authorization: Zoho-oauthtoken 1e...' \
--form 'file=@"/X:/PdfS/ZOHO_PRE.PDF"'

Re: Subuir un fichero a un servidor

PostPosted: Fri Dec 01, 2023 6:02 am
by miarcod
Bueno de momento he conseguido subir el fichero desde la línea de comandos

Code: Select all  Expand view

:sendfile
set location=https://www.zohoapis.eu/crm/v5/Leads/594992000001640002/Attachments
 set header1="Authorization: Zoho-oauthtoken 1000.4e9ea07b78fce8a9ce3fdbf514"
   set form1="file=@'/D:\ZOHO_PRE.PDF'"
   set form1='file=@"/D:/ZOHO_PRE.PDF"'
   set form1='file=@"/D:/ZOHO_PRE.PDF"'
   set form1=file="/D:/ZOHO_PRE.PDF"
   set form1=file=@"D:/ZOHO_PRE.PDF"
   set form1=file=@"D:\ZOHO_PRE.PDF"
   set form1=file=@"/D:/ZOHO_PRE.PDF"
   set form1=file=@"X:ZOHO_PRE.PDF"

curl --location %location% --header %header1% --form %form1%

 


Esto es lo que le envio desde la línea de comandos, pero para conseguirlo he tenido que copiar el fichero en la ruta actual y ejectuar la orden sin path

Ahora voy a ver generar el comando y ejecutarlo desde el programa pero lo ideal sería poder hacerlo desde HARBOUR internamente sin la intervención de otros programas

Gracias a todos por vuestra ayuda
;)

Re: Subuir un fichero a un servidor

PostPosted: Fri Dec 01, 2023 10:56 am
by JoseLuis
Buenas

Yo, desde hace años utilizo el siguiente programa para subir ficheros por ftp, no he tenido ningún problema. Es para xharbour, son ficheros de texto. Este código lo saqué de éste foro ha ce años.

Code: Select all  Expand view

#include "fivewin.ch"
#include "xbrowse.ch"
#include "Directry.ch"

memvar Publicas
//*************************
Function subirf()
local aAlias,j,cNom,cFicheros,cdestino,cArcOri,cNomarc
local Ficheros:=Directory( Publicas:cUnidad+"ficheros\*.txt" )
Local oFTP
local oUrl
Local cServer := Publicas:cserver //change ftpserver to the real name or ip of your ftp server
Local cUser := Publicas:cUser // change ftpuser to an valid user on ftpserer
Local cPassword := Publicas:cPassword // change ftppass to an valid password for ftpuser
Local cUrl := "ftp://" + cUser + ":" + cPassword + "@" + cServer
cUser:= strtran(cUser,"@","&at;")
oUrl := tUrl():New( cUrl )
IF At( "@", cUser ) > 0
   oUrl:cUserID := strtran(cUser,"&at;","@")
   oUrl:cPassword := cPassword
ENDIF
oFTP := tIPClientFtp():New( oUrl, .F. )
oFTP:nConnTimeout := 20000
oFTP:bUsePasv := .T.
if .not. oFtp:open()
  msginfo("ftp error "+oFtp:LastErrorMessage())
  return(.f.)
endif
oFTP:Open( )
aAlias:=cargaAlias()
dbUseArea(.T.,,Publicas:cUnidad+Publicas:cSubd+"\PROVE",aAlias[21],.T.)
(aAlias[21])->(OrdSetFocus("Codigo"))
(aAlias[21])->( dbGotop() )
if len (ficheros)>0
  for j = 1 to len (Ficheros)
    cNom := SUBSTR(Ficheros[J,1], -12 )
    aadd(Ficheros[j],nombre(cNom,aAlias))
  next j
  cFicheros:=Selecciona(Ficheros)
  if len(cFicheros)>0
     if msgyesno("QUIERES SUBIR AL SERVIDOR "+alltrim(str(len(cFicheros)))+" FICHEROS?","AVISO")
       FOR J := 1 TO LEN(cFicheros)
          cArcOri :=  Publicas:cUnidad+"ficheros\"+Ficheros[cFicheros[J],1]
          cNomArc := SUBSTR(cArcOri,-12 )
          oftp:UploadFile( cARcOri,Publicas:cRutafiles+cNomarc )
          Ferase( cArcOri )
        NEXT J
        msgwait("
Hemos subido "+alltrim(str(len(cFicheros)))+" Ficheros al servidor","AVISO",2)
     else
       msgwait("
No has elegido ningun fichero para subir al servidor","AVISO",2)
     endif
  else
     msgwait("
No has elegido ningun fichero para la subida al servidor","AVISO",2)
  endif
else
  msgwait("
Lo siento no hay ficheros para Subir al Servidor","AVISO",2)
endif
(aAlias[21])->( dbClosearea() )
*borrafich()
return nil
//*******************************
Static function nombre(busca,aAlias)
local nombrec
busca:=substr(busca,1,5)
(aAlias[21])->(Dbseek(busca))
nombrec:=(aAlias[21])->Nombre
Return nombrec
//***********************
static Function Selecciona(carchivo)
 LOCAL oDlg, oLbx,oWnd,oboton,aselect:=0
 LOCAL oFont, oMultiSel, oBmpOn, oBmpOff,oBrw

    DEFINE BITMAP oBmpOn  RESOURCE "
bmpenable"
    DEFINE BITMAP oBmpOff RESOURCE "
bmpdisable"

    DEFINE FONT oFont NAME 'MS Sans Serif' SIZE 0,-8
    DEFINE DIALOG oDlg FROM 1, 1 TO 25,90 TITLE "
Subida de ficheros al servidor"

    @ 10,10 XBROWSE oBrw SIZE -55,-10 PIXEL OF oDlg ;
            COLUMNS 1,6 ;
        DATASOURCE carchivo;
            CELL LINES NOBORDER
     
    WITH OBJECT oBrw
      :l2007                  := .F.
      :lFooter                := .T.
      :lHScroll               := .T.
      :nColDividerStyle       := LINESTYLE_NOLINES
      :nRowDividerStyle       := LINESTYLE_NOLINES
      :nRowHeight             := 20
      :lAllowColSwapping      := .F.
      :lColDividerComplete    := .T.
      :nStretchCol   := STRETCHCOL_WIDEST
      :bClrSelFocus    := { || { CLR_RED, nRGB( 255, 188, 130 ) } }
      :aCols[1]:cHeader:= "
Fichero "
      :aCols[2]:cHeader:= "
Cliente "
      :cTitle:= "
Selecciona los ficheros para subir al servidor"
      :nMarqueeStyle = MARQSTYLE_HIGHLROWMS //6
      :lRecordSelector = .T.
      :aCols[1]:bFooter       := { || "
Total archivos: " + LTrim( TransForm( obRw:nLen, "999,999" ) ) }
      :CreateFromCode()
    END

  @ 30,300  BTNBMP OF oDlg SIZE 50,15 2007 NOBORDER PROMPT "
Ninguno"       FONT oFont LEFT RESOURCE "aspa"    ACTION (obrw:aSelected:={},oDlg:End())
  @ 100,300 BTNBMP OF oDlg SIZE 50,15 2007 NOBORDER PROMPT "
Subir"         FONT oFont LEFT RESOURCE "copidat" ACTION (aselect:=1,oDlg:End())  
    ACTIVATE DIALOG oDlg CENTERED
    RELEASE BITMAP oBmpOn, oBmpOff
    RELEASE FONT oFont
    return iif(aselect=1,obrw:aSelected,obrw:aSelected:={})

//******
Function borrafich()
local lficheros,llongitud,lnumfiles,i

/*
lficheros := Array( ADir( Publicas:cUnidad+"
*.log" ) )
llongitud := Array( ADir( Publicas:cUnidad+"
*.log" ) )
lnumFiles := aDir (Publicas:cUnidad+"
*.log", lficheros, llongitud)
   FOR i:=1 TO lnumFiles
        Ferase(Publicas:cUnidad+lficheros[i])
   NEXT
*/
lficheros := Array( ADir( "
ftp*.log" ) )
llongitud := Array( ADir( "
ftp*.log" ) )
lnumFiles := aDir ("
ftp*.log", lficheros, llongitud)
   FOR i:=1 TO lnumFiles
        Ferase(lficheros[i])
   NEXT

Return nil