Subir Archivo a un FTP

Colapsar
X
 
  • Tiempo
  • Mostrar
Limpiar Todo
nuevos mensajes
  • asclevius
    Member
    • ago
    • 54

    #1

    Subir Archivo a un FTP

    Buenos Días FORO!!!!

    De casualidad alguien tiene un programa de ejemplo para subir un archivo a un servidor FTP?

    Tengo que hacer unas consultar y subir un archivo .TXT a este servidor pero no tengo ni idea de como hacerlo o como abordar este requerimiento.

    Cualquier ayuda es bienvenida


    Gracias por todo!!!
  • SidV
    Usuario Avanzado
    • oct
    • 1761

    #2
    En principio cualquier cliente de FTP te sirve.
    Si usas Firefox, podes hasta usar Filezilla :P

    Si googleas "free ftp client" te aparecen muchos.
    Es cuestión de gustos.

    Yo la verdad no me acuerdo cual usaba... hace mucho q no subo nada a un FTP.

    Saludos

    PD: re-leí tu consula, vos debes querer un ZETA en abap para subir algo a un servidor FTP. jajajajajajajajajajajjaja tomen mi respuesta con humor entonces jajajajajajjaa xD

    Comentario

    • asclevius
      Member
      • ago
      • 54

      #3
      Originalmente publicado por SidV
      En principio cualquier cliente de FTP te sirve.
      Si usas Firefox, podes hasta usar Filezilla :P

      Si googleas "free ftp client" te aparecen muchos.
      Es cuestión de gustos.

      Yo la verdad no me acuerdo cual usaba... hace mucho q no subo nada a un FTP.

      Saludos

      PD: re-leí tu consula, vos debes querer un ZETA en abap para subir algo a un servidor FTP. jajajajajajajajajajajjaja tomen mi respuesta con humor entonces jajajajajajjaa xD
      JAJAJAJAJAJAJA claro, un Z para tener como ejemplo!!!!

      Comentario

      • SidV
        Usuario Avanzado
        • oct
        • 1761

        #4
        Te fijaste este ejemplo?
        Samples illustrate software features and capabilities and provide other helpful resources to show how an SAP solution may be extended to meet customer needs. - SAP Samples

        Comentario

        • asclevius
          Member
          • ago
          • 54

          #5
          Cual ejemplo?
          Donde?????

          Comentario

          • SidV
            Usuario Avanzado
            • oct
            • 1761

            #6
            Originalmente publicado por asclevius
            Cual ejemplo?
            Donde?????
            Media pila, en el link que te pasé sale un ejemplo

            Código:
            REPORT zftptrasfr
            NO STANDARD PAGE HEADING LINE-SIZE 255.
             
            ************************************************************************
            *T Y P E S
            ************************************************************************
            TYPES:
            BEGIN OF x_cmdout,
              line(100) TYPE c,
            END OF x_cmdout.
             
            TYPE-POOLS : slis.
             
            ************************************************************************
            *    D A T A
            ************************************************************************
            *data specifications of FTP server
             
            *Handler and Key
            DATA: w_cmd(40) TYPE c,
                  w_hdl TYPE i,
                  w_logid TYPE zda_log_ipl VALUE 1,
                  w_key TYPE i VALUE 26101957,
                  w_slen TYPE i,
                  wa_iplftp TYPE ztbl_ipl_ftp,
                  it_iplftp TYPE STANDARD TABLE OF ztbl_ipl_ftp,
                  wa_cmdout TYPE x_cmdout,
                  it_cmdout TYPE STANDARD TABLE OF x_cmdout.
             
            *Constant declarations
            CONSTANTS:  c_dest TYPE rfcdes-rfcdest VALUE 'SAPFTPA',
                        c_host(11) TYPE c VALUE '172.XX.X.XX',
                        c_ftp(6) TYPE c VALUE 'FTPDIRECTORY',
                        c_sap(16) TYPE c VALUE '/sap/inbound/SAPDIRECTORY'.
             
            ************************************************************************
            *    P A R A M E T E R S
            ************************************************************************
             
            SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
            PARAMETERS: p_user(30) TYPE c LOWER CASE ,
                        p_pwd(30) TYPE c LOWER CASE ,
                        p_host(64) TYPE c LOWER CASE DEFAULT c_host ,
                        p_edi TYPE zedi, " 5-character domain containing EDI profiles
                        p_ftp TYPE e_dexcommfilepath LOWER CASE DEFAULT c_ftp,
                        p_sap TYPE esefilepath LOWER CASE DEFAULT c_sap.
            SELECTION-SCREEN END OF BLOCK b1.
             
            ************************************************************************
            *AT SELECTION SCREEN Events
            ************************************************************************
             
            AT SELECTION-SCREEN OUTPUT.
             
              LOOP AT SCREEN.
                CASE screen-name.
                  WHEN 'P_PWD'."Set the password field as invisible
                    screen-invisible = '1'.
                    MODIFY SCREEN.
                ENDCASE.
              ENDLOOP.
             
            ************************************************************************
            *    S T A R T - O F - S E L E C T I O N
            ************************************************************************
             
            START-OF-SELECTION.
             
            *Connect to the FTP server.
              PERFORM ftp_connect.
             
            *Find all files in the directory and store inside the Log table
              PERFORM log_files.
             
            *Check for transfer of files to FTP.
              IF it_iplftp[] IS INITIAL.
                MESSAGE text-003 TYPE 'I'.
                LEAVE LIST-PROCESSING.
              ENDIF.
             
            *Change the local save directory and download to SAP application server.
              PERFORM move_files.
             
            *Close the connection
              PERFORM close_ftp.
             
            ************************************************************************
            *END-OF-SELECTION
            ************************************************************************
            END-OF-SELECTION.
             
            *Display report.
              PERFORM disp_res.
             
            *&---------------------------------------------------------------------
            *& Form FTP_CONNECT
            *&---------------------------------------------------------------------
            *Make a connection to the FTP server
            *----------------------------------------------------------------------
            FORM ftp_connect .
             
              SET EXTENDED CHECK OFF.
              w_slen = strlen( p_pwd ).
             
              CALL FUNCTION 'HTTP_SCRAMBLE'
                EXPORTING
                  source      = p_pwd
                  sourcelen   = w_slen
                  key         = w_key
                IMPORTING
                  destination = p_pwd.
             
              CALL FUNCTION 'FTP_CONNECT'
                EXPORTING
                  user            = p_user
                  password        = p_pwd
                  host            = p_host
                  rfc_destination = c_dest
                IMPORTING
                  handle          = w_hdl
                EXCEPTIONS
                  not_connected   = 1
                  OTHERS          = 2.
              IF sy-subrc <> 0.
            *Message will arise in case of any issues in connecting to the FTP server.
                MESSAGE text-e01 TYPE 'I'.
                LEAVE LIST-PROCESSING.
              ENDIF.
             
            ENDFORM. " FTP_CONNECT
            *&---------------------------------------------------------------------
            *& Form LOG_FILES
            *&---------------------------------------------------------------------
            *find all the files in the home directory
            *----------------------------------------------------------------------
            FORM log_files .
             
            *Change directory to the FTP directory for LUPIN
              CONCATENATE 'cd' p_ftp INTO w_cmd SEPARATED BY space.
             
              CALL FUNCTION 'FTP_COMMAND'
                EXPORTING
                  handle        = w_hdl
                  command       = w_cmd
                  compress      = 'N'
                TABLES
                  data          = it_cmdout
                EXCEPTIONS
                  tcpip_error   = 1
                  command_error = 2
                  data_error    = 3
                  OTHERS        = 4.
              IF sy-subrc <> 0.
                MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
              ENDIF.
              REFRESH it_cmdout.
              CLEAR w_cmd.
              w_cmd = 'ls'.
             
              CALL FUNCTION 'FTP_COMMAND'
                EXPORTING
                  handle        = w_hdl
                  command       = w_cmd
                  compress      = 'N'
                TABLES
                  data          = it_cmdout
                EXCEPTIONS
                  tcpip_error   = 1
                  command_error = 2
                  data_error    = 3
                  OTHERS        = 4.
              IF sy-subrc <> 0.
                MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
              ENDIF.
             
            *All customized checks for file to be placed here.
              LOOP AT it_cmdout INTO wa_cmdout FROM 4.
             
            *Check the command line for a file
                CHECK wa_cmdout-line+68(4) EQ '.txt'.
             
            *Move all the files to the FTP table
                wa_iplftp-file_nm = wa_cmdout-line+39(33).
                wa_iplftp-log_id = w_logid.
             
            *Currently the transfer date/time will be taken
                wa_iplftp-fdate = sy-datum."WA_CMDOUT-LINE+39(8).
                wa_iplftp-ftime = sy-uzeit."WA_CMDOUT-LINE+48(6).
                wa_iplftp-ernam = sy-uname.
             
                APPEND wa_iplftp TO it_iplftp.
             
              ENDLOOP.
              REFRESH it_cmdout.
             
            ENDFORM. " LOG_FILES
            *&amp;---------------------------------------------------------------------
            *&amp; Form MOVE_FILES
            *&amp;---------------------------------------------------------------------
            FORM move_files .
             
              DATA : l_indx TYPE i.
             
              CLEAR w_cmd.
              CONCATENATE 'lcd' p_sap INTO w_cmd SEPARATED BY space.
             
            *Change the local directory to the sap inbound directory
              CALL FUNCTION 'FTP_COMMAND'
                EXPORTING
                  handle        = w_hdl
                  command       = w_cmd
                  compress      = 'N'
                TABLES
                  data          = it_cmdout
                EXCEPTIONS
                  command_error = 1
                  tcpip_error   = 2.
              IF sy-subrc <> 0.
                MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
              ENDIF.
             
              REFRESH it_cmdout.
            *Move each file from FTP to SAP inbound directory
              LOOP AT it_iplftp INTO wa_iplftp WHERE stat EQ space OR
              stat EQ 'CR'.
             
                l_indx = sy-tabix.
             
                CLEAR w_cmd.
                REFRESH it_cmdout.
             
                CONCATENATE 'get' wa_iplftp-file_nm INTO w_cmd SEPARATED BY space.
             
                CALL FUNCTION 'FTP_COMMAND'
                  EXPORTING
                    handle        = w_hdl
                    command       = w_cmd
                    compress      = 'N'
                  TABLES
                    data          = it_cmdout
                  EXCEPTIONS
                    command_error = 1
                    tcpip_error   = 2.
                IF sy-subrc <> 0.
                  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
                ENDIF.
             
                READ TABLE it_cmdout INTO wa_cmdout INDEX 2.
                IF sy-subrc EQ 0.
                  IF wa_cmdout-line CS 'command successful'.
                    wa_iplftp-stat = 'CR'.
                    wa_iplftp-mess = text-004.
                  ELSE.
                    wa_iplftp-stat = 'EF'.
                    wa_iplftp-mess = text-005.
                  ENDIF.
                ENDIF.
             
                MODIFY it_iplftp FROM wa_iplftp INDEX l_indx.
            *delete from FTP
                CLEAR w_cmd.
                CONCATENATE 'delete' wa_iplftp-file_nm INTO w_cmd SEPARATED BY space.
             
                CALL FUNCTION 'FTP_COMMAND'
                  EXPORTING
                    handle        = w_hdl
                    command       = w_cmd
                    compress      = 'N'
                  TABLES
                    data          = it_cmdout
                  EXCEPTIONS
                    command_error = 1
                    tcpip_error   = 2.
                IF sy-subrc <> 0.
                  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
                ENDIF.
              ENDLOOP.
             
            *Insert all table entries.
              INSERT ztbl_ipl_ftp FROM TABLE it_iplftp.
              IF sy-subrc NE 0.
                MESSAGE text-006 TYPE 'I'.
              ENDIF.
             
            ENDFORM. " MOVE_FILES
            *&---------------------------------------------------------------------
            *& Form CLOSE_FTP
            *&---------------------------------------------------------------------
            FORM close_ftp .
             
              CALL FUNCTION 'FTP_DISCONNECT'
                EXPORTING
                  handle = w_hdl.
             
              CALL FUNCTION 'RFC_CONNECTION_CLOSE'
                EXPORTING
                  destination = c_dest
                EXCEPTIONS
                  OTHERS      = 1.
              IF sy-subrc <> 0.
                MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
              ENDIF.
             
            ENDFORM. " CLOSE_FTP
            *&amp;---------------------------------------------------------------------
            *&amp; Form DISP_RES
            *&amp;---------------------------------------------------------------------
            *Display the output
            *----------------------------------------------------------------------
            FORM disp_res .
             
              DATA : l_layout TYPE slis_layout_alv.
             
              l_layout-colwidth_optimize = 'X'.
             
            *Display table contents of updated files
              CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
                EXPORTING
                  i_callback_program = sy-repid
                  i_structure_name   = 'ZTBL_IPL_FTP'
                  is_layout          = l_layout
                TABLES
                  t_outtab           = it_iplftp
                EXCEPTIONS
                  program_error      = 1
                  OTHERS             = 2.
              IF sy-subrc <> 0.
                MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
              ENDIF.
             
            ENDFORM. " DISP_RES
            Hay que leer, no esperes todo servido.

            Saludos

            Comentario

            • asclevius
              Member
              • ago
              • 54

              #7
              Disculpame, no vi el link!!!! lo confundi con tu firma, de nuevo, disculpame

              Comentario

              • asclevius
                Member
                • ago
                • 54

                #8
                Solución

                Hola a todos

                Coloco links que me fuerón de utilidad para subir un TXT a un FTP y para crear un TXT en un FTP partiendo de una tabla interna.









                http://abaptman.blogspot.com/2008/08...-archivos.html
                http://www.mundosap.com/foro/showthread.php?t=39158


                y esta fue mi solución



                Código:
                Types utilizados en la clase
                
                
                  TYPES: BEGIN OF comm,
                    line TYPE c LENGTH 100,
                  END OF comm .
                
                  TYPES: BEGIN OF ftp_comm,
                    line(132) TYPE c,
                  END OF ftp_comm .
                
                
                ********************************************************************************
                
                Parametros del metodo
                
                I_VL_NAME_FILE_ACT	Importing	Type	CHAR100
                I_VL_NAME_FILE_MAT	Importing	Type	CHAR100
                C_TI_MATERIALES_TXT	Changing	Type	TRUXS_T_TEXT_DATA
                C_TI_ACTIVI_TXT	                  Changing	Type	TRUXS_T_TEXT_DATA
                
                ********************************************************************************
                
                * ____________________________________________________
                * Definicion de variables locales y constantes.
                * ____________________________________________________
                
                  "Constantes para realizar conexion con el FTP
                  "______________________________________________
                
                  CONSTANTS: c_rfc_destino TYPE rfcdest VALUE 'SAPFTP',
                             c_key         TYPE i       VALUE '26101957'.
                
                
                  DATA:
                
                        "Variables locales de conexión
                        "________________________________________
                
                        vl_handle          TYPE i,
                        vl_slen            TYPE i,
                        vl_command_index   TYPE i,
                        vl_usuario(30)     TYPE c VALUE 'apps',
                        vl_password(30)    TYPE c VALUE 'Asdfgh1234$%',
                        vl_host(64)        TYPE c VALUE '190.216.137.34',
                        vl_comando(100)    TYPE c,
                        vl_dir_ftp(15)     TYPE c VALUE 'archivos_planos',
                
                        "Tablas Internas
                        "________________________________________
                
                        ti_ftp_comm        TYPE TABLE OF ftp_comm.
                
                
                * ______________________________________________________________
                * &&&&&&&&&&&&&&&&&&&&&&&    Logica del proceso    &&&&&&&&&&&&&&
                * ______________________________________________________________
                
                
                
                CLEAR vl_comando.
                
                
                
                  "Longitud de caracteres
                  "______________________________________
                
                  vl_slen = strlen( vl_password ).
                
                  "Encriptación de la contraseña
                  "______________________________________
                
                  CALL FUNCTION 'HTTP_SCRAMBLE'
                    EXPORTING
                      source      = vl_password
                      sourcelen   = vl_slen
                      key         = c_key
                    IMPORTING
                      destination = vl_password.
                
                  "Conexión con el servidor FTP
                  "______________________________________
                
                  CALL FUNCTION 'FTP_CONNECT'
                    EXPORTING
                      user            = vl_usuario
                      password        = vl_password
                      host            = vl_host
                      rfc_destination = c_rfc_destino
                    IMPORTING
                      handle          = vl_handle.
                
                
                  "Validar si se realizo la conexión
                  "___________________________________________
                
                  IF sy-subrc NE 0.
                
                    MESSAGE 'Error de conexión' TYPE 'E'.
                
                  ELSE.
                
                    "Se Agrega el Comando a la Ruta de donde se
                    "va a dejar el archivo.
                    "_________________________________________
                
                    CONCATENATE 'cd' vl_dir_ftp '' INTO vl_comando SEPARATED BY space.
                
                    CALL FUNCTION 'FTP_COMMAND'
                      EXPORTING
                        handle        = vl_handle
                        command       = vl_comando
                      TABLES
                        data          = ti_ftp_comm
                      EXCEPTIONS
                        tcpip_error   = 1
                        command_error = 2
                        data_error    = 3.
                
                *
                *    "Se agrega el Comando al Nombre del
                *    "Archivo que se va a dejar.
                *    "_________________________________________
                *
                *    CLEAR wa_comandos.
                *    CONCATENATE 'put' '<"ruta servidor de aplicacion SAP con nombre archivo y extension">' INTO commands-line SEPARATED BY space.
                *    APPEND wa_comandos TO ti_comandos.
                *
                *
                *Para cuando se quiera pasar una lista de comandos a ejecutar con solo una función
                *
                *
                *  IF NOT ti_comandos IS INITIAL.
                *
                *    CALL FUNCTION 'FTP_COMMAND_LIST'
                *      EXPORTING
                *        handle        = vl_handle
                *      IMPORTING
                *        command_index = vl_command_index
                *      TABLES
                *        commands      = ti_comandos       "tabla con los comando a ejecutar
                *        data          = ti_ftp_com
                *      EXCEPTIONS
                *        command_error = 1
                *        tcpip_error   = 2
                *        data_error    = 3.
                *
                *  ENDIF.
                
                
                
                
                    "Datos de la tabla materiales a un txt en el
                    "ftp
                    "_____________________________________________
                
                
                    CALL FUNCTION 'FTP_R3_TO_SERVER'
                      EXPORTING
                        handle         = vl_handle
                        fname          = i_vl_name_file_act
                        character_mode = 'X'
                      TABLES
                        text           = c_ti_materiales_txt
                      EXCEPTIONS
                        tcpip_error    = 1
                        command_error  = 2
                        data_error     = 3
                        OTHERS         = 4.
                    IF sy-subrc <> 0.
                * Implement suitable error handling here
                    ENDIF.
                
                
                    "Datos de la tabla actividades a un txt en el
                    "ftp
                    "_____________________________________________
                
                    CALL FUNCTION 'FTP_R3_TO_SERVER'
                      EXPORTING
                        handle         = vl_handle
                        fname          = i_vl_name_file_mat
                        character_mode = 'X'
                      TABLES
                        text           = c_ti_activi_txt
                      EXCEPTIONS
                        tcpip_error    = 1
                        command_error  = 2
                        data_error     = 3
                        OTHERS         = 4.
                    IF sy-subrc <> 0.
                * Implement suitable error handling here
                    ENDIF.
                
                
                  ENDIF.
                
                
                  ""Terminar la conexión con servidor ftp.
                  "____________________________________________
                
                  CALL FUNCTION 'FTP_DISCONNECT'
                    EXPORTING
                      handle = vl_handle.
                Espero que le sea de utilidad a Alguien

                Comentario

                Trabajando...