SFTP files to a file server.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SFTP files to a file server.
# 1  
Old 03-03-2015
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 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.


Moderator's Comments:
Mod Comment Moved to shell scripting forum and removed specifics for OS.
Duplicate thread, but for Linux closed.

Last edited by rbatte1; 03-03-2015 at 06:07 AM.. Reason: Added CODE tags
# 2  
Old 03-03-2015
man expect
# 3  
Old 03-03-2015
Using expect is not the way to go really. Can you consider setting up SSH keys? If you can exchange them, you can get sftp to sign on without prompting. You can also then use the -b flag to batch up the commands you want to run with the sftp session.


Does this help?
Robin
# 4  
Old 03-03-2015
There's a reason hardcoding passwords in scripts is so hard, and why things like passwordless SSH key exchange were developed.

It's insecure.

Use SSH keys. It's why they've been created.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with moving files on remote server using sftp

I need to sftp a file ABC_sysdate.csv (File name with system date and timestamp) to a temporary directory on the remote server and once the file is copied I've to move the file from temporary directory to the main directory with the same name. I have to generate a new file every hour and repeat... (6 Replies)
Discussion started by: srinup
6 Replies

2. HP-UX

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:-... (2 Replies)
Discussion started by: happysingh
2 Replies

3. Linux

SFTP files to a server from Linux.

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:- ... (1 Reply)
Discussion started by: happysingh
1 Replies

4. 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

5. 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

6. Shell Programming and Scripting

Sftp some files from windows server to UNIX server

hi i need to transfer some files from windows server to unix server using SFTP. but before transferring the files, i need to check the existence of a particular file in the remote directory (say r_dir1). if the file is present, then SFTP all the files. after SFTPing the files from the remote... (1 Reply)
Discussion started by: vinit raj
1 Replies

7. Shell Programming and Scripting

SFTP files from one server to another

Hi, I want to transfer files from 1 server to another server using sftp. Earlier what I use to do is transfer files on the same server using mv command. Pls help. (6 Replies)
Discussion started by: chetancrsp18
6 Replies

8. Shell Programming and Scripting

SFTP to transfer files from one server to another

Hello, i have to write a script to perform sftp from the remote server to another server. the files which are at the remote location are huge data log files which should be transfered to my server in a particular folder. could you please provide me the general code (simple )... (1 Reply)
Discussion started by: urfrnddpk
1 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. Solaris

how to get multiple files using sftp from a windows server

I need to get multiple files from a windows server to a solaris server using sftp, I tried it but only can get one file at a time ( I'm unable to use a wild card character using sftp) hoe do i do this. any light on this is appreciated. Ram. (3 Replies)
Discussion started by: ramky79
3 Replies
Login or Register to Ask a Question