Shell script to sftp files to file server.


 
Thread Tools Search this Thread
Operating Systems HP-UX Shell script to sftp files to file server.
# 1  
Old 03-03-2015
Shell script to sftp files to file server.

Hi,

I am looking for a shell script to sftp to a file server and copy all the files from a directory after the script is run.
The server name should be a user input parameter and of-course the username/password as well. Rest all should be handled by the script.

I tried with below snippet:-
Code:
echo "FTP'ing the CSV output to file server now.."

echo "Please enter the FTP server name:"
read ftpservername

echo "Please enter the username:"
read username

sftp $username@$ftpservername

However, the problem is:- When it is run, it brings on the sftp password prompt - which I dont want. I would like to handle password as well automatically within script as user input and then copy files from a particular directory to a directory on the file server (This is also a user input).

Any idea how this can be handled with-in the script? The script should automatically take care of establishing a successful SFTP session to the server and then transfer the files.

Help with sample script will be highly appreciated.

Thanks.

Last edited by Scott; 03-05-2015 at 04:21 PM.. Reason: Please use code tags
# 2  
Old 03-05-2015
Create an ssh key with ssh-keygen! More info:
Code:
man ssh-keygen

sftp is optimized for interactive use. Perhaps you can copy the files with scp? Both use the ssh protocol.
# 3  
Old 03-05-2015
after keygen it will generate 2 files example id_dsa and id_dsa.pub

you need to copy the public key to remote server you want to login rename the file to be called authorized_keys (remove all end of line control characters)

it should work on unix and linux but becareful of windows and maybe aix as they use something called tectia ssh the method is similar but syntax is different I forget already how it is.
This User Gave Thanks to sparcguy For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP files to a file server.

Hi, I am looking for a shell script to sftp to a file server and copy all the files from a directory after the script is run. The server name should be a user input parameter and of-course the username/password as well. Rest all should be handled by the script. I tried with below... (3 Replies)
Discussion started by: happysingh
3 Replies

2. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

3. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

4. Shell Programming and Scripting

Shell script to transfer file via SFTP

Hi all, I'm trying to do a script to transfer file between my server and an external server via SFTP protocol. It doesn't use rsa key, but password. When I run the script, it throw back a prompt that request me to put the password. How should I do for automatic login? Pleaes help :( ... (2 Replies)
Discussion started by: Kapom
2 Replies

5. Shell Programming and Scripting

i want to execute shell script on remote server with in sftp session

Hi, I want to execute shell script with in sftp session for remote server. like i have a shell script test.sh that is on local server.i want to execute that script on remote server sftp user@192.168.56.10 sftp> test.sh ---execute for remote server not for local server. sftp... (3 Replies)
Discussion started by: SAUD PASHA
3 Replies

6. Shell Programming and Scripting

SFTP to server through Shell Script

I am sftp-ing to a server through a shell script from my local machine. sftp user@host put out.txt bye On executing the script, it prompts to enter the password, and after giving the password it successfully connects to the host.But the problem is that the remaining statements after the... (1 Reply)
Discussion started by: Kishore_1
1 Replies

7. Shell Programming and Scripting

shell script to get sftp files

did anyone knows a script to get a latest file in a folder,,i try to get the newest file at a folder via sftp and i want to make a crontab to do this once a day,,can someone give me the script to get the latest file?? (5 Replies)
Discussion started by: Cellscript
5 Replies

8. Shell Programming and Scripting

Use cURL in shell script and get most recent file from remote server using SFTP

I have been trying to implement the following shell script -- sftp to remote server get list of files in the directory sftp get the most recent listed file exit This script will be scheduled to be executed everyday using CRON or CONTROL-M and the need is to have absolutely no human... (7 Replies)
Discussion started by: toobrown1
7 Replies

9. UNIX for Dummies Questions & Answers

File Missing When Grabbing Files from SFTP Server using SCP Command

Hi, I have this problem where sometimes my files would go missing when I schedule my crontab to run the SCP command to get file from the SFTP server. My crontab will run the scripts at an interval of 3 minutes (between the two scripts) The following is the setting in my crontab. ... (1 Reply)
Discussion started by: gingervitus
1 Replies

10. Shell Programming and Scripting

SFTP Shell Script from a Unix server to another

I am facing a typical issue for transfering files through secured FTP (SFTP) for example, i have three different servers a,b & c server A - where data file resides Server B - where Unix shell program resides here(source server) server C - Destination server I wanted to run the shell... (1 Reply)
Discussion started by: kumarm
1 Replies
Login or Register to Ask a Question