Skip to Content
Author's profile photo Former Member

Write File on SFTP Server from SAP

SAP ABAP has the Functionality to write/Read on FTP server,but there is no functionality in ABAP  to read /Write on SFTP server.You only have the option of XI/PI to Write/Read on SFTP location.

I Googled and managed to Read/Write on SFTP server from SAP Application Server with the help of an open Source FTP client.

Below are the Steps to write on SFTP location

Assumptions

Operting System : Windows

Database : Oracle

SAP Version : Netweaver 7.0 ECC 6.0

Step 1

Download and install WinSCP.You can download WINSCP from  http://winscp.net/eng/download.php 

Step 2

Check the connectivity from SAP Server to SFTP server with WinSCP

Create the WinSCP Login and maintain the connection string

/wp-content/uploads/2013/10/winscp1_291247.gif

maintain the logon details and Save

you can either check the connectivity with GUI or with Command Prompt

Command to check connectivity is : open sftp://<User>:<Password>@<SFTP_Server> -hostkey=”ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx”

after checking the connectivity create a batch script of WinSCP commands.you can find the list of available commands of winscp from http://winscp.net/eng/docs/scripting

a Sample script will give you an idea how it looks like

Open NotePad and write the content and Save it witj .txt extension.

# Automatically abort script on errors

option batch abort

# Disable overwrite confirmations that conflict with the previous

option confirm off

# Connect using a password

# open sftp://user:password@example.compassword@example.com -hostkey=”ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx”

# Connect

open sftp://user@example.com//user@example.com -hostkey=“ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx”

# Change remote directory

cd /home/user

# Force binary mode transfer

option transfer binary

# Download file to the local directory d:\

get examplefile.txt d:\

# Disconnect

close

# Connect as a different user

open sftp://user2@example.com//user2@example.com

# Change the remote directory

cd /home/user2

# Upload the file to current working directory

put d:\examplefile.txt

# Disconnect

close

# Exit WinSCP

exit

Step 3

Create command in SM69

Go to transaction SM69 and create external operating system command.make sure to tick additional parameters and trace

/wp-content/uploads/2013/10/winscp4_291328.gif

you can test the command by executing it.

Step 4

Call the newly created external Command using FM : SXPG_COMMAND_EXECUTE

you can then write the program and call the external command which will execute and Write/Read the File on SFTP server.


Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member
      Blog Post Author
      Author's profile photo Darshan panchal
      Darshan panchal

      Hi,

       

      Thanks for your valuable information.

       

      I am sad to say that it is not illustrative.

       

      what info needed to be entered in definition section of tcode sm69 is not clear.

       

      Also sample script is not descriptive.

       

      Please provide more info.

       

      Thanks,

      Darshan.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Darshan

       

      You have to maintain the following entries in SM69

       

      Command Name : Any Name starting with Y or Z

       

      OS Command : Program Name with the Path i.e the location where WINSCP is installed

       

      Paramters for OS Command : additional parameters needed for execution of command in which you wiil define the script Name

      Author's profile photo Darshan panchal
      Darshan panchal

      Hi Muhammad ,

       

      Do wee need to install WinSCP on Application server OS & save script as well.

       

      Please guide me on this.

       

      Thanks,

      Darshan.

      Author's profile photo Manu Bhutani
      Manu Bhutani

      Hi Darshan,

      Did you install WinSCP?

       

      Regards