generic sftp script creation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting generic sftp script creation
# 1  
Old 04-18-2011
generic sftp script creation

I am trying to work out if it is possible to create a generic scrip which will allow sftp to be run for connecting to a host machine based on a parameter and to retrieve files based on a batch file. The batch file bit I am fine with, I can make that work. The are I'm not so sure about is how to parameterise the host machine and connection details.
I've trawled through previous threads on this, but they seem to relate to connecting to a single machine.
Does anyone have any suggestions? Smilie
# 2  
Old 04-22-2011
I really never use sftp. I always just go with scp instead. Looking at the man page for sftp I see that batch files are designed for use with non-interactive authentication... so I assume you have that working. This script:
Code:
#! /usr/bin/ksh

CONTROL="Solaris1:/var/adm:messages
Linux1:/var/log:messages"


exec 4>&1
for line in $CONTROL ; do
        echo $line | IFS=: read HOST DIR FILE
        sftp $HOST  >&4 2>&4 |&
        print -p cd $DIR
        print -p get $FILE ${HOST}.${FILE}
        print -p bye
        wait
done
exit 0

does not use batch files but also depends on non-interactive authentication. I tested it and it worked. (Well, I did have have permission to get /var/log/messages on the Linux system... but other than that it worked.)

I still say that a simple scp would have been better.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Generic script to load file details(ls -ltr) in to a database.

All, I am trying to create a report on the duration of an ETL load from the file arrival to the final dump in to a database for SLA's. Does anyone have any guidance or ideas on how metadata can be extracted; information of a file: like file name, created timestamp, count of records and load... (1 Reply)
Discussion started by: pradeepp
1 Replies

2. UNIX for Beginners Questions & Answers

Sftp file creation time

Hi Team, Could you please let me know ,how to find the file creation date time in SFTP server. i tred like , ls -ltr command only availble and not available like ls --full-time test.txt please help? Thanks (7 Replies)
Discussion started by: bmk123
7 Replies

3. Shell Programming and Scripting

Sftp file creation date and time

Hi Team, How to get the file creation date and time in SFTP server we can able to type ls -ltr command only SFTP server. Generally we type ls --full-time test.txt we will get the date and time , same way how to do in SFTP server after connected. Thanks (1 Reply)
Discussion started by: bmk123
1 Replies

4. Shell Programming and Scripting

Generic script to recursively cd into directories and git pull

Hi all, I'm trying to write a script to recursively cd into my Git projects and pull them, and will later expand it to build my projects as well. I'm having a bit of trouble with my current script, as I want to supply a command line argument to tell it which branch to check out. I can hard... (2 Replies)
Discussion started by: Cows
2 Replies

5. Shell Programming and Scripting

Required help on a Generic File-watcher script

Hi All, Good morning... I have prepared a shell script which will monitor files in a certain folder and if available, SCP it to a destination path. Now the challenge I'm facing is my script is currently SCP-ing to only a single destination path. Wherever different destination path is in... (1 Reply)
Discussion started by: saps19
1 Replies

6. Red Hat

SFTP User creation in Redhat Linux/UNIX

SFTP user creation step… Create a group # groupadd sftp_users If the users doesn’t exist on system , use below command : # useradd -G sftp_users -s /sbin/nologin username # passwd username For already existing users , use below usermod command : # usermod –G... (1 Reply)
Discussion started by: taherahmed
1 Replies

7. Shell Programming and Scripting

SFTP-how to log individual sftp command error while executing shell script

Hi, I have situation where i need to automate transferring 10000+ files using sftp. while read line do if ; then echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt fi done< files.txt sftp -b sftpCommand.txt stu@192.168.2.1 The above... (1 Reply)
Discussion started by: noobrobot
1 Replies

8. Shell Programming and Scripting

Generic script for Querying a DB

I have a few databases that i need to get some basic output from... so I'll be returning 1 or 2 records from a variety of different databases and the input queries will always differ. What im looking for is a generic script that I can use across of the databases. Theory being i have: ... (2 Replies)
Discussion started by: atelford
2 Replies

9. Shell Programming and Scripting

Generic Shell Script to Archive a file

Would appreciate if any one can paste a generic schell script to archive a file with date stamp by passing the file with fullpath as parameter For Eg. /apps/scripts/Archive_File.sh /data_home/project_home/file.txt this should place the file in the following directory ... (8 Replies)
Discussion started by: mak1600
8 Replies

10. Shell Programming and Scripting

How to transfer files (By using generic script) when using sftp

I have written generic script to transfer files from one machine to other machine(By passing the command line arguments like server name, user name ,location of the files, file names etc) but when i am using sftp, what are the things I have to specify in the code Is it necessary to specify... (0 Replies)
Discussion started by: gsri
0 Replies
Login or Register to Ask a Question