How to write a shell script to sftp a file from one linux server to another

Submitted 3 years, 7 months ago
Ticket #170
Views 904
Language/Framework Unix
Priority Medium
Status Closed

I require to sftp files from one linux server to another using password authentication. I need to call this script from SAP BODS by passing input parameters

Submitted on Sep 14, 20

Just to make sure, why cant you go for password less mechanism?. Basically using SSH key - Vengat 3 years, 7 months ago

Thanks for your reply.. But the remote server belongs to a different team in our project.. they have provided me with user name, pwd and the sftp server details - meena 3 years, 7 months ago

Thanks for your reply.. But the remote server belongs to a different team in our project.. they have provided me with user name, pwd and the sftp server details - meena 3 years, 7 months ago

Is SAP BODS hosted on LINUX server? - scott 3 years, 7 months ago

I tried few options like spawn sftp in my shell script but it's not working for me... I tried to connect the remote server and sftp ed a file using sftp commands which was working but not sure how to implement in a shell script - meena 3 years, 7 months ago

Yes BODS is hosted on Linux server - meena 3 years, 7 months ago
add a comment

1 Answer

Verified

@ Meena I would suggest, as SAP BODS hosted on Linux server, then add the 2 LINUX machine where you need to copy the files into SAP BODS .ssh_key file.

Generally, we have create the private key pair between 2 systems and added into ssh_pub file where SAP BODS hosted. Now without using password , you can transfer the files among 3 machines. So generally this one is the recommended approach.

Or

May be try sshpass ,pass with sshpass -p "your password" at the beginning of your scp command

sshpass -p "your password" scp ./file1.txt servername/file.txt

But this one is not recommended one.

Submitted 3 years, 7 months ago

Is this fulfilled your requirement?. May be try the one which I posted above.

- scott 3 years, 7 months ago

install this in your unix machine sudo apt-get install sshpass. Also you commented on Answer that is only for providing answers. Please delete that.

- scott 3 years, 7 months ago

Sure thanks

- meena 3 years, 7 months ago

Welcome, regarding code snippets, after install you can use the above sshpass command in your shell script. Hopefully it should work.

- scott 3 years, 7 months ago

If the solution helps you, then kindly close the ticket.

- scott 3 years, 7 months ago

@Scott..I am still waiting for the sshpass to be installed since I don't have sudo access to install it. Once done I will test this and close the ticket.

- meena 3 years, 7 months ago

@Meena Thanks for letting me know, please make sure to respond in a week. Otherwise ticket will be closed.

- scott 3 years, 7 months ago

As we dont get any response from the user, we are closing the ticket. Respective points will be distributed to the techions.

- Vengat 3 years, 7 months ago


Latest Blogs