Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

sftp file compression

Former Member
0 Kudos

Hi All,

Im using SFTP batch mode to read a series of commands from an input batchfile instead of stdin.

Example :

sftp -b batchfile user@host

Right now, I need to enable the compression for the file before sending to SFTP server.

I need to add in the switch -C in my Abap program. How to I achieve that?

Add the switch at the back of the code as below?? Please advise.Thanks.

sftp -b batchfile user@host -C

Edited by: Blue Sky on Oct 1, 2008 6:54 AM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

I might not be giving u the final solution, but I can help you with compression of the file.

the below code can be made use of, inorder to compress a file.


TYPES:
t_xline(2048) TYPE x, "BINARY FILES

BEGIN OF t_line,
line(1024) TYPE c,
END OF t_line. "CONTENT

DATA:
size type i.

DATA:
data_tab TYPE STANDARD TABLE OF t_xline,
text_tab TYPE STANDARD TABLE OF t_line.

DATA:
input_x type xstring, "BINARY CONTENT INPUT
output_x type xstring. "BINARY OUTPUT OUTPUT

data : CL_ZIP type ref to CL_ABAP_ZIP .


DATA:
name type string.

name = 'c:\error.doc'. "<-- Insert full path of application server

CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
EXPORTING
FILENAME = name
FILETYPE = 'BIN'
IMPORTING
FILELENGTH = size
CHANGING
DATA_TAB = data_tab.


CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
INPUT_LENGTH = size
IMPORTING
BUFFER = input_x
TABLES
BINARY_TAB = data_tab.

CREATE OBJECT cl_zip.

cl_zip->ADD(
EXPORTING
NAME = name
CONTENT = input_x
)
.

cl_zip->SAVE(
RECEIVING
ZIP = output_x
)
.

REFRESH data_tab.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = output_x
IMPORTING
OUTPUT_LENGTH = size
TABLES
BINARY_TAB = data_tab
.
DATA:
lw_output_path TYPE string.

lw_output_path = 'c:\myfile.zip'. " specify the application server path where u want to create zip file.


CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
EXPORTING
BIN_FILESIZE = size
FILENAME = lw_output_path
FILETYPE = 'BIN'
CHANGING
DATA_TAB = data_tab
.

Regards,

Kiran

2 REPLIES 2

Former Member
0 Kudos

Hi,

I might not be giving u the final solution, but I can help you with compression of the file.

the below code can be made use of, inorder to compress a file.


TYPES:
t_xline(2048) TYPE x, "BINARY FILES

BEGIN OF t_line,
line(1024) TYPE c,
END OF t_line. "CONTENT

DATA:
size type i.

DATA:
data_tab TYPE STANDARD TABLE OF t_xline,
text_tab TYPE STANDARD TABLE OF t_line.

DATA:
input_x type xstring, "BINARY CONTENT INPUT
output_x type xstring. "BINARY OUTPUT OUTPUT

data : CL_ZIP type ref to CL_ABAP_ZIP .


DATA:
name type string.

name = 'c:\error.doc'. "<-- Insert full path of application server

CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
EXPORTING
FILENAME = name
FILETYPE = 'BIN'
IMPORTING
FILELENGTH = size
CHANGING
DATA_TAB = data_tab.


CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
INPUT_LENGTH = size
IMPORTING
BUFFER = input_x
TABLES
BINARY_TAB = data_tab.

CREATE OBJECT cl_zip.

cl_zip->ADD(
EXPORTING
NAME = name
CONTENT = input_x
)
.

cl_zip->SAVE(
RECEIVING
ZIP = output_x
)
.

REFRESH data_tab.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = output_x
IMPORTING
OUTPUT_LENGTH = size
TABLES
BINARY_TAB = data_tab
.
DATA:
lw_output_path TYPE string.

lw_output_path = 'c:\myfile.zip'. " specify the application server path where u want to create zip file.


CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
EXPORTING
BIN_FILESIZE = size
FILENAME = lw_output_path
FILETYPE = 'BIN'
CHANGING
DATA_TAB = data_tab
.

Regards,

Kiran

Former Member
0 Kudos

Hi Kiran,

Thanks for your code.

My requirement is to retain the code and just require to add the switch -C in somewhere else to achieve the compression.

Is my current way to append the -C at the back of the batch mode code is correct?