FileServlet serving from FTP

Hello!
I'm trying to create a bean that opens a PDF file from another FTP server. I have it open from a local path, but can't get it to open from a FTP host. Your help is appreciated.
Thanks in advance!
-Tony
package aiView;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLConnection;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import sun.net.ftp.FtpClient;
public class FileServlet extends HttpServlet {
    private FtpClient m_client;
    private String host = "";
    private String user = "";
    private String password = "";
    private String sDir = "";
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException {
            m_client = new FtpClient(host);
            m_client.login(user, password);
            m_client.cd(sDir);
            m_client.binary();
        // Define base path somehow. You can define it as init-param of the servlet.
        String filePath = "/files";
        //Not working
        //String filePath = m_client.cd(sDir);
        // String filePath = getServletContext().getRealPath("/WEB-INF/files");
        // Get file name from request.
        String fileName = request.getParameter("name")+".pdf";
        // Check if file name is supplied to the request.
        if (fileName != null) {
            // Strip "../" and "..\" (avoid directory sniffing by hackers!).
            fileName = fileName.replaceAll("\\.+(\\\\|/)", "");
        } else {
            // Do your thing if the file name is not supplied to the request.
            // Throw an exception, or show default/warning page, or just ignore it.
            fileName = "filenotfound.pdf";
            response.sendRedirect("FileNotFoundError.jsp");
            return;
        // Prepare file object.
        File file = new File(filePath, fileName);
        // Check if file actually exists in filesystem.
        if (!file.exists()) {
            // Do your thing if the file appears to be non-existing.
            // Throw an exception, or show default/warning page, or just ignore it.
            //fileName = "filenotfound.pdf";
            response.sendRedirect("FileNotFoundError.jsp");
            return;
        // Get content type by filename.
        String contentType = URLConnection.guessContentTypeFromName(fileName);
        // If content type is unknown, then set the default value.
        // For all content types, see: http://www.w3schools.com/media/media_mimeref.asp
        if (contentType == null) {
            contentType = "application/pdf";
        // Prepare streams.
        BufferedInputStream input = null;
        BufferedOutputStream output = null;
        try {
            // Open file file.
            input = new BufferedInputStream(new FileInputStream(file));
            int contentLength = input.available();
            // Init servlet response.
            response.reset();
            response.setContentLength(contentLength);
            response.setContentType(contentType);
            response.setHeader(
                    "Content-disposition", "attachment; filename=\"" + fileName + "\"");
            output = new BufferedOutputStream(response.getOutputStream());
            // Write file contents to response.
            while (contentLength-- > 0) {
                output.write(input.read());
            // Finalize task.
            output.flush();
        } catch (IOException e) {
            // Something went wrong?
            e.printStackTrace();
        } finally {
            // Gently close streams.
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    // This is a serious error. Do more than just printing a trace.
            if (output != null) {
                try {
                    output.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    // This is a serious error. Do more than just printing a trace.
}Edited by: ynotlim333 on Oct 19, 2007 1:17 AM
Edited by: ynotlim333 on Oct 19, 2007 1:19 AM

Well,Alright here is an example which i would try to implement.
Say,there is a table in dataBase which has below schema
TABLE fileTable{
    fileId --- PK -- Auto Generated;
    fileNameWithPath - varchar2(200);
    createdDate -- DATE;
}and their is a DTO Mapped to that table called FileDTOBean
public class FileDTOBean implements serializable{
   private String fileId = "";
   private String fileNameWithPath ="";
   private Date createdDate = null;
    /** Setters & getters for respective properties */
}Assuming that their is a DAO called FileServiceDAO which has method called getFileDTO(String fileId) which return an instance of FileDTOBean for a given fileId.
by executing a query like
"select fileId,fileNameWithPath,createdDate from fileTable where fileId = ?"and you would be using a dedicated Business Object for the same purpose.
FileServiceDelegateImpl.java:
=====================
package com.webapp.commons.delegate.impl;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryUsage;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import org.apache.commons.net.ftp.FTPClient;
  * @Author : RaHuL ShArMa
  * @Version : v1.0
/**The Delegate class could be used as a Bsuiness Object which provides services to give access to different stored in Database/local system/remote mapped network drive/FTP registered by specfic fileId from database*/
public class FileServiceDelegateImpl implements FileServiceDelegate{
          private static FileServiceDelegate fsd = null;
          private static FileServiceDAO fd = null;
          protected FileServiceDelegateImpl(){ 
               this.fd = FileServiceDAO.getCurrentInstance();
          public static synchronize FileServiceDelegate getCurrentInstance(){
                if(fsd == null)
                  fsd = new FileServiceDelegateImpl();
                return fsd;
          public void exportFTPFile(HttpServletResponse reponse,String ftpUri,String userName,String password,String fileId,boolean content)throws Exception{
                  InputStream fis = null;                 
                  BufferedInputStream input = null;
                  BufferedOutputStream output = null;       
                  int contentLength = 0;
                  FileDTOBean fdto = this.fd.getFileDto(fileId);
                  FTPClient ftpClient = null;
                  try{
                      String fileName = fdto.getFileName();
                      ftpClient = new FTPClient();
                      ftpClient.connect(ftpUri);
                      ftpClient.login(ftpUri);
                      fis =  ftpClient.retrieveFileStream(fileName);
                        // Getting the Mime-Type
                       String contentType = URLConnection.guessContentTypeFromStream(fis);          
                       if(contentType == null)
                            contentType = "application/octet-stream";
                        fis = new FileInputStream(fdto.getFileNameWidPath());
                        contentLength = fis.available(); 
                        // Trying to get the Generic Buffer Size w.r.t other factors
                        int readSize = this.getGenericSize(contentLength.available());                           
                        input = new BufferedInputStream(fis,readSize);
                        response.setContentType(contentType);
                        response.setContentLength(contentLength);
                        if(content) 
                           response.setHeader("Content-Disposition","attachment;filename=\"+fdto.getFileNameWidPath()+"\");
                        output = new BufferedOutputStream(response.getOutputStream(),readSize);
                        // output the streaming request
                        this.streamData(input,output,readSize);  
                   }catch(Exception e) {          
                        throw new Exception(e.getCause());
         /**The actual method which sends back the respective response to the supposed client by picking up the content from       
         the specified*/
         public void exportFile(HttpServletResponse reponse,String fileId,boolean content) throws Exception{
                  InputStream fis = null;                 
                  BufferedInputStream input = null;
                  BufferedOutputStream output = null;       
                  int contentLength = 0;
                  FileDTOBean fdto = this.fd.getFileDto(fileId);
                  URL url = null;
                  URLConnection urlConn = null;
                  try{
                        String filePath = fdto.getFileNameWidPath().trim();
                         if(!filename.startsWith("ftp://"))
                           fis = new FileInputStream(filname);
                         else{
                            url = new URL(filePath);
                            urlConn = url.openConnection(); 
                            fis = urlConn.getInputStream();
                        // Getting the Mime-Type
                       String contentType = URLConnection.guessContentTypeFromStream(fis);           
                       if(contentType == null)
                            contentType = "application/octet-stream";
                        contentLength = fis.available(); 
                        // Trying to get the Generic Buffer Size w.r.t other factors
                        int readSize = this.getGenericSize(contentLength.available());                           
                        input = new BufferedInputStream(fis,readSize);
                        response.setContentType(contentType);
                        response.setContentLength(contentLength);
                        if(content) 
                           response.setHeader("Content-Disposition","attachment;filename=\"+fdto.getFileNameWidPath()+"\");
                        output = new BufferedOutputStream(response.getOutputStream(),readSize);
                        // output the streaming request
                        this.streamData(input,output,readSize);  
                   }catch(Exception e) {          
                        throw new Exception(e.getCause());
          /**The actual method which sends back the respective response to the supposed client by picking up data from the database*/
          public void exportDBData(HttpServletResponse reponse,String fileId,boolean content) throws Exception{
                  FileInputStream fis = null;                 
                  BufferedInputStream input = null;
                  BufferedOutputStream output = null;       
                  int contentLength = 0;
                  FileDTOBean fdto = this.fd.getFileDto(fileId);
                  if(fdto == null)
                    return;
                  try{
                        // Getting the Mime-Type
                        String contentType = fdto.getContentType();
                        bis = new ByteArrayInputStream(fdto.getData());
                        contentLength = bis.available(); 
                        // Trying to get the Generic Buffer Size w.r.t other factors
                        int readSize = this.getGenericSize(contentLength);                           
                        input = new BufferedInputStream(bis,readSize);
                        response.setContentType(contentType);
                        response.setContentLength(contentLength);
                        if(content) 
                           response.setHeader("Content-Disposition","attachment;filename=\"+fileName+"\");
                        output = new BufferedOutputStream(response.getOutputStream(),readSize);
                        // output the streaming request
                        this.streamData(input,output,readSize);  
                   }catch(Exception e) {          
                        throw new Exception(e.getCause());
        /**Outputs given results as per decided constraits*/ 
        public void streamData(BufferedInputStream input,BufferedOutputStream output,int readSize)throws Exception{
             try{
                byte buffer[] = new byte[readSize]; 
                int nByteRead = 0;
                while((nByteRead = input.read(buffer)) != -1)
                    output.write(buffer);                         
                output.flush();
             }catch(Exception exp){
               exp.printStackTrace(); 
               throw new Exception(exp.getCause());
             }finally{
                  if(input != null){
                        try {
                            input.close();
                        } catch (Exception ie) {
                         ie.printStackTrace(); 
                            throws new Exception(ie.getCause());
                  if (output != null) {
                          try {
                             output.close();
                          } catch (Exception ie) {                     
                             throws new Exception(ie.getCause());         
                  input = null;
                  output = null;
     /**Deciding Just by applying Best memory usage constraint and one can change the logic accordingly
      * with respective other factors like network load and etc
     public synchronize int getGenericSize(int length){
             int bufferSize = 512;
             MemoryUsage heapUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); 
             double usageFactor =    (heapUsage.getInit() - heapUsage.getUsed()) / heapUsage.getMax();            
             bufferSize = (int)(length * usageFactor);
             if(bufferSize <= 512)
                  bufferSize = 512;
             else if(buffer >= 4096) 
                  bufferSize = 4096;                 
             return bufferSize;                            
}and the code in your Servlet/JSP/Struts Action/Backing bean would be like.
public void processAction(HttpServletRequest request,HttpServletResponse.......)throws Exception{
    String fileId = request.getParameter("fid");
        lets assume file associated to fileId is "ftp://username:[email protected]/movie1Poster.jpg;type=i"
    if(fileId == null)
         throw new Exception("invalid fileid passed");
    //Assuming ServiceLocator returns instance FileServiceDelegateImpl
    FileServiceDelegate fsd = ServiceLocator.get(FileServiceDelegate.class);
     fsd.exportFile(response,fileId,false);
    /* or try using for secure FTP Access
         fsd.exportFTPFile(response,"ftp.foobar.com","username","password",fileId,false);
}all you wud do in you jsp is to access respective file with
http://HOST:appPort/webContextName/urlPatternAssociated?fid=<FileId>
eg:
<img src="FileServlet?fid=F13245" width="300" height="300" />
<img src="FileAction.do?fid=F13245" width="300" height="300" />Hope this might help :)
REGARDS,
RaHuL

Similar Messages

  • Problem while reading the file from FTP server

    Hi Friends,
    I have a problem while fetching files from FTP server.
    I used FTP_Connect, FTP_COMMAND function modules. I can able to put the files into FTP server.
    but I cant able to pick the files from FTP server.
    anyone have faced similar issues kindly let me know.
    Thanks
    Gowrishankar

    Hi,
    try this way..
    for reading the file using FTP you need to use different unix command ..
    Prabhuda

  • How to read .xls file from FTP server t oInternal table

    Hi
    am using the FTP_SERVER_TO_R3 to read xls file from FTP server to internal table
    but the data i get in LT_TEXT is special characters.
    CALL FUNCTION 'FTP_SERVER_TO_R3'
    EXPORTING
    handle = hdl
    fname = f_name "ProdDataFromCRM.xls.
    * CHARACTER_MODE = 'X'
    * IMPORTING
    * BLOB_LENGTH =
    TABLES
    BLOB = lt_text
    * TEXT = lt_text
    EXCEPTIONS
    TCPIP_ERROR = 1
    COMMAND_ERROR = 2
    DATA_ERROR = 3
    OTHERS = 4
    can any one help me out to get the exact data..
    Really appreciate your quick response..
    Thank You

    Hi, if you really retrieve an excel file, you can not see the data in ABAP. You may see them in Excel. For this you may use
    CALL METHOD document->open_document_from_table
    of the interface i_oi_document_proxy for OLE objects. You can access the data with reference to the interface i_oi_spreadsheet.
    Please check [Desktop Office Integration (BC-CI)|http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCIOFFI/BCCIOFFI.pdf] for details.
    But, who knows, perhaps you want "And Now For Something Completely Different".
    Regards
    Clemens

  • Need to copy .txt file from FTP server and downloaded on local server directory.

    I need to figure out a way to copy .txt file from ftp server in local server directory using sql jobs.

    Below links will help achieving it:
    https://www.virtualobjectives.com.au/sqlserver/ftp_scripts.htm
    http://www.mssqltips.com/sqlservertip/2884/sql-server-integration-services-ssis-ftp-task-for-data-exchange/

  • How to read XL file from FTP server

    Hi all,
    I have a requirement like to read file from FTP server using path
    ftp:
    10.212......\DTR\DTR_ Accounted_Out
    and again save  other file in same location ,
    to doing this RFC connection is required?
    give a  procedure or program to do this requirement ..
    To create rfc for FTP which connection type can i use ?
    Give complete settings to create rfc destination

    Hi Rakhi,
    Use the below code to check if you have received the proper data.
    call function 'FTP_SERVER_TO_R3' "Get data as character instead of BLOB
        exporting
          handle         = hdl
          fname          = docid
          character_mode = 'X'
        tables
          text           = chardata.
    If the data is incorrect, it is possible that you are in the wrong directory.
    Use
    call function 'FTP_COMMAND'
        exporting
          handle        = hdl
          command       = 'cd mydir\mysubdir' "cd <space> your path
        tables
          data          = result
        exceptions
          tcpip_error   = 1
          command_error = 2
          data_error    = 3.
    Regards,
    Jovito.

  • Problem in download file from FTP server

    Hi
    I want to download a file from FTP server for that i am using the apache FTP module but i am not getting how to download a file with that api i can dispaly the list of files and folders but not able to download the file or folder can any one help me in this
    Thanks
    Ninad

    Hi
    I think you miss understood something I am writing a program to download the file in Java where i have used the jakarta.apache api for that and getting problem in that bellow is the code where I have written to print the directory & file names but I don't know how to download the file
    FTPClient ftpConnection = new FTPClient();
    ftpConnection.connect(host);
    ftpConnection.login(FTPConnection.userName,FTPConnection.password);
    FTPFile fileList[] = ftpConnection.listFiles();
    for(int i=0;i<fileList.length;i++)
         System.out.println(fileList.getName());
    thanks
    Ninad

  • How to get file from FTP Server using File Control

    Hi,
    Any one did getting file from FTP Server?
    Please let me know any one help me.
    I would need to get file from FTP Server.
    Thanks,
    Madhu

    Yes I have done that. But In FTP Server I cannt read file, because no previliges. Only I need to copy file from FTP Server to local server then only I can read that file.
    I tried all options using FileConrol(getFiles(),read()).
    getFiles() - It wont copy the file, it give information about file.
    read() - I dont have previliges to read the file.
    Please tell me any other procedure would be there for getting file from FTPServer.
    Thanks,
    Madhu

  • Downloading excel file from FTP Server to Application Server

    Hi,
    I have to get data from an excel file available on FTP server into an Internal table.Can I use FTP_SERVER_TO_R3 to do so.
    Please let me know if there are any function modules available to do this.
    Thanks,
    Prasuna.

    Dear Gayatri,
    You can get the file from FTP to internal table...
    I am sending you the code with inline comments ....Hope this will be helpful to you.
    Data: lv_key           TYPE i VALUE 26101957.
    Data: lv_password(30)  TYPE c.
      i_rfc_destination = 'SAPFTP'.
      lv_length = STRLEN( i_password ).
    CALL FUNCTION 'HTTP_SCRAMBLE'
        EXPORTING
          SOURCE      = i_password "give ftp server pwd
          sourcelen   = lv_length
          key         = lv_key
        IMPORTING
          destination = lv_password.
      CALL FUNCTION 'FTP_CONNECT'
        EXPORTING
          user            = i_user "give ftp user name
          password        = lv_password
          host            = i_host
          rfc_destination = i_rfc_destination
        IMPORTING
          handle          = lv_ftp_handle
        EXCEPTIONS
          not_connected   = 1
          OTHERS          = 2.
        CONCATENATE 'cd' i_folder_path INTO lv_cmd SEPARATED BY space.
    *i_folder path is the path in ftp server where file is  stored
        CALL FUNCTION 'FTP_COMMAND'
          EXPORTING
            handle        = lv_ftp_handle
            command       = lv_cmd
          TABLES
            data          = result
          EXCEPTIONS
            command_error = 1
            tcpip_error   = 2.
         lv_blob_length = 392.
         TRANSLATE i_filename TO LOWER CASE.
          CALL FUNCTION 'FTP_SERVER_TO_R3'
            EXPORTING
              handle      = lv_ftp_handle
              fname       = i_filename          "give required file name
            IMPORTING
              blob_length = lv_blob_length
            TABLES
              blob        = lt_dummy.
    Regards
    Sajid

  • Pulling data file from FTP server

    Hello All,
    I would require help on how to read a data file stored in FTP server from my ABAP program. The type of file is .csv, I need this file to actually upload the data coming into SAP. Please suggest how do I solve this.
    Thanks,
    Sunil Kumar

    hi,
    You will find the link useful...
    http://www.sap-img.com/ab003.htm
    Also, check out the standard program ... RSEPSFTP
    The flow should be..
    Open a FTP connection by FM- FTP_CONNECT
    Execute a command on the FTP server by FM - FTP_COMMAND
    and finally  Close the connection by FM - FTP_DISCONNECT
    Regards,
    Richa

  • Reading a file from ftp server

    Hi
    I am able to put file on ftp server using ftp adapter.But same settings are not working while polling file on ftp.
    Do i need to do some settings for get operation??

    Hi,
    Check the file permissions and for testing give all read/write/execute permissions to the file to be read from FTP. Also check the file modification date of the file.
    Check for the logs at 2 places for any error messages:
    - SOA server diagnostics logs
    - FTP server logs
    You can also enable the FINEST level of Adapter logs for adapters and see for the detailed errors in the diagnostic logs.
    FMW Console > right click soa-infra > Logs > Log Configuration > expand oracle.soa > set Trace32 : FINEST for oracle.soa.adapter
    Regards,
    Neeraj Sehgal

  • [HELP] Download file from FTP server

    hi,
    I want to write a java program that can download and upload files from ftp server. Currently I only manage to upload a file to ftp server but i cant download file from ftp server. Here is the source code that only allow user to upload file. Anyone can give me some guidelines so that my program can download and also upload file? thx.
    import java.io.*;
    import java.net.*;
    public class FTPUpload {
    private static final int CTRLPORT = 21;
    private static Socket ctrlSocket;
    private static PrintWriter ctrlOutput;
    private static BufferedReader ctrlInput;
    private static byte[] localHostAddress;
    public final static String DIR = "C:\\zip\\";
    public static void main(String[] args) {
    try {
    String host = "192.168.1.1";
    String loginName = "testuser";
    String password = "password";
    String dirName = "/home/testuser";
    String fileName = "hello.zip";
    ctrlSocket = new Socket(host, CTRLPORT);
    localHostAddress = ctrlSocket.getLocalAddress().getAddress();
    ctrlOutput = new PrintWriter(ctrlSocket.getOutputStream());
    ctrlInput = new BufferedReader(new InputStreamReader(ctrlSocket.getInputStream()));
    ctrlOutput.println("USER " + loginName);
    ctrlOutput.flush();
    ctrlOutput.println("PASS " + password);
    ctrlOutput.flush();
    ctrlOutput.println("CWD " + dirName);
    ctrlOutput.flush();
    ctrlOutput.println("TYPE I");
    ctrlOutput.flush();
    FileInputStream fis = new FileInputStream(DIR + fileName);
    Socket dataSocket = dataConnection("STOR " + fileName);
    OutputStream outstr = dataSocket.getOutputStream();
    int n;
    byte[] buff = new byte[1024];
    while ((n = fis.read(buff)) > 0) {
    outstr.write(buff,0,n);
    dataSocket.close();
    fis.close();
    ctrlOutput.close();
    ctrlInput.close();
    ctrlSocket.close();
    }catch (Exception e) {
    e.printStackTrace();
    private static Socket dataConnection(String ctrlcmd)
    throws IOException,UnknownHostException {
    String cmd = "PORT ";
    ServerSocket serverDataSocket = new ServerSocket(0,1);
    for (int i=0;i<4;i++) {
    cmd = cmd + (localHostAddress[i] & 0xff) + ",";
    cmd = cmd + (((serverDataSocket.getLocalPort())/256) & 0xff)
    + ","
    + (serverDataSocket.getLocalPort() & 0xff);
    ctrlOutput.println(cmd);
    ctrlOutput.flush();
    ctrlOutput.println(ctrlcmd);
    ctrlOutput.flush();
    Socket dataSocket = serverDataSocket.accept();
    serverDataSocket.close();
    return dataSocket;
    }

    Or just use a java.net.URL("ftp://...) ..., get its input stream, and away you go ...

  • Upload XL file from FTP server

    Hi All,
    Can anybady help me, how to upload Excel file from FTP server.
    Thanks
    Sri
    Edited by: srikanthn on Apr 14, 2010 6:31 PM

    Hello
    How about using SAPFTP?
    I hope SAP note 130106 will guide you on this.
    Thanks
    koju

  • Read file from ftp SERVER(NON SAP) into an internal table

    Hi all,
    I need to read the data from an excel file which was uploaded from ftp (i.e different server) into an SAP internal table by using FTP connections.
    Actually i am already getting text file data successfully.
    But only when reading in excel file that is presented in JDA server.
    Facing problem to read excel file data from JDA server.
    Pls help me.
    How can we go ahead ?
    Kindly suggest with the help of some code.

    Hi Lokesh,
    Currently I need to interface JDA and SAP.
    Can you kindly recommend how to handle this?

  • Download file from FTP Server to Application Server

    Hi Friends,
    Using the standard SAP Program RSFTP002, I was able to download the file to my local PC. But my requirement is to download the file from FTP to application server.
    For RSFTP002, I am passing the username, password, host and in command 1 I am passing lcd :\temp, command 2 get filename. The file gets downloaded into c:\temp. If I do the same passing the app server path in command 1 as /usr/sap/tmp I get an error that pass cannot be found.
    Anyone please help me how to donload the file from ftp to app server.
    Thanks,
    Deepthi

    If I remember correctly the activation type on the technical settings tab must be set to "start on application server" in transaction SM59 for the RFC destination for the FTP server.  This should allow the files to be transferred to/from the application server.
    Regards,
    Steve.

  • Regaring file from FTP server to application server

    Hi frnds,
    Below is my code where i am transferring Presentation server file to FTP server.
    Now i want to transfer that file from FTP server to application server.
    any help. below i am providing my code.
    <code>
    *& Report  demo
    report  z_demo_ftp.
    Variables declaration
    data : mi_handle type i,
           pwd       type char30,
           slen      type i,
           key type i value 26101957,
           it_file2 type filetable,
           w_file2 like   line of it_file2,
           l_rc type i,
           v_index type i,
           v_file(30) type c,
           v_path(100) type c,
           v_path_tmp(100) type c.
    *Internal table declaration
    data: begin of mtab_data occurs 0,
           line(132) type c,
          end of mtab_data.
    Selection scree parameters
    parameters: p_file type string default 'C:\'.
    Get the file path
    at selection-screen on value-request for p_file.
      data: p_file1 type string.
      p_file1 = p_file.
      call method cl_gui_frontend_services=>file_open_dialog
        exporting
          default_filename        = p_file1
        changing
          file_table              = it_file2
          rc                      = l_rc
        exceptions
          file_open_dialog_failed = 1
          cntl_error              = 2
          error_no_gui            = 3
          not_supported_by_gui    = 4.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      else.
        read table it_file2 into w_file2 index 1.
        p_file = w_file2-filename.
        clear w_file2.
        refresh it_file2.
        split p_file at '\' into table it_file2.
        describe table it_file2 lines v_index.
        read table it_file2 into w_file2 index v_index.
        concatenate 'put' w_file2-filename into v_file separated by space.
        delete it_file2 index v_index.
        clear w_file2.
        loop at it_file2 into w_file2.
        if sy-tabix = 1.
        v_path = w_file2-filename.
        endif.
        if sy-tabix ge 2.
        concatenate v_path '\' w_file2 into v_path.
        endif.
        endloop.
        concatenate 'lcd' v_path into v_path_tmp separated by space.
      endif.
    Start of selection
    start-of-selection.
    pwd = 'file456'.
    slen = strlen( pwd ).
    call function 'HTTP_SCRAMBLE'
      exporting
        source      = pwd
        sourcelen   = slen
        key         = key
      importing
        destination = pwd.
    Connect to FTP
    call function 'FTP_CONNECT'
      exporting
        user            = 'client'
        password        =  pwd
        host            = 'saturn'
        rfc_destination = 'SAPFTP'
      importing
        handle          = mi_handle
      exceptions
        not_connected   = 1
        others          = 2.
    if sy-subrc = 0.
    Excute FTP command
    call function 'FTP_COMMAND'
        exporting
          handle        = mi_handle
          command       = 'cd staff
        tables
          data          = mtab_data
        exceptions
          tcpip_error   = 1
          command_error = 2
          data_error    = 3
          others        = 4.
    Excute FTP command
          call function 'FTP_COMMAND'
        exporting
          handle        = mi_handle
          command       = v_path_tmp
        tables
          data          = mtab_data
        exceptions
          tcpip_error   = 1
          command_error = 2
          data_error    = 3
          others        = 4.
    Excute FTP command
      call function 'FTP_COMMAND'
        exporting
          handle        = mi_handle
          command       = v_file
        tables
          data          = mtab_data
        exceptions
          tcpip_error   = 1
          command_error = 2
          data_error    = 3
          others        = 4.
      if sy-subrc = 0.
        loop at mtab_data.
          write: / mtab_data.
        endloop.
      endif.
    endif.
    *FTP disconnect
    call function 'FTP_DISCONNECT'
      exporting
        handle = mi_handle
      exceptions
        others = 1.call function 'FTP_DISCONNECT'
      exporting
        handle = mi_handle
      exceptions
        others = 1.
          end-of-selection.
    </code>
    so what more code shuld i write.
    regards,
    kamal

    Hi Che Eky  ,
                          Actually the above code is for putting the presentation server file to FTP Server.
    But now i need to Put the same file present in the FTP server to Application server.
    So any help or code which will be helpful.
    regards,
    kamal

Maybe you are looking for

  • Why can't I play some of my movies?

    I have a number of movies in my library that I bought from iTunes. I can't play half of them, despite having bought them a while ago and watching them several times. The window opens when I click on them, but then it just sits there, and it won't pla

  • FYI: R.I.P. MobileMe

    The 'grace period' for downloading from the iDisk and migrating the account has now ended: any files still on MobileMe have been deleted and migration is no longer possible.

  • Need Answer on ALE Service Layer

    In my  cusomized outbound program i am using a function module MASTER_IDOC_DISTRUBUTE to generate the IDOCS. I am passing the both sender and reciever values to the function module MASTER_IDOC_DISTRUBUTE then distribution model in BD64 is not require

  • Error in oracle application server connection

    The following error appears when I try to add and test oracle application server connection in JDev 10.1.3 : Error getting OC4J Process for: opmn-home+oc4j-Orbit-7777-default: Error while parsing OPMN dump in XML format: XML Parse Exception: tag=[nul

  • Infinity Speed Drops

    Hi all. I sincerely wish that I had taken the time to read up on BT before moving my broadband services over. Unfortunately in my area the choice is rather limited and the offer of Infinity was, in principle, too good to be true. I had my service ins