Scripting multiple file "puts" in sFTP...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripting multiple file "puts" in sFTP...
# 1  
Old 03-13-2006
Scripting multiple file "puts" in sFTP...

I need to send multiple files to a remote server via sFTP. I had everything set up to connect and send a single file automatically using a batch file and key authentication. Recently, however, the process has changed and we now need to send multiple files, one at a time, pausing for up to ten minutes in between files. I am having trouble passing a variable from my .ksh script to the sftp command. Once I pass control over to the batch file for sftp, it only recognizes sftp commands. I can't use a wildcard like "file*.RPT" because it will send all of the files up at once, without pausing in between them.

Does anyone have any experience scripting with sFTP that can shed some light on this for me?
# 2  
Old 03-14-2006
Looks like a job for a here-document. I don't use sFTP but in old fashioned unsecure ftp you would do something like:

Code:
for file in *.txt
do
ftp -n <destinationserver><<EOF
user <userid password>
cd <destinationdirectory>
put ${file}
bye
EOF
sleep 600
done

The commands between <<EOF and EOF (you can use any character string but the start and end strings must be identical with no leading/trailing spaces) are executed as if you typed them in at the keyboard

hope this helps

cheers
# 3  
Old 03-14-2006
Cbish68,

To sleep for any amount of time, you would have to run a sleep command. Why don't you use a batch file. Try doing this:
Code:
$ cat batchfile
cd /tmp
lcd /etc
put issue
!sleep 10
put motd
bye

$ sftp -b batchfile username@hostname

# 4  
Old 03-14-2006
Quote:
Originally Posted by thestevew
Looks like a job for a here-document. I don't use sFTP but in old fashioned unsecure ftp you would do something like:

hope this helps

cheers
Thanks, but sFTP works a bit differently than standard FTP. In order to run the sFTP script from cron, unattended, you must use sFTP with a batchfile. The batchfile only understands sFTP commands. It will not interpret variables, etc. You can't script sFTP inline like you can with standard FTP.
# 5  
Old 03-14-2006
Quote:
Originally Posted by blowtorch
Cbish68,

To sleep for any amount of time, you would have to run a sleep command. Why don't you use a batch file. Try doing this:
Code:
$ cat batchfile
cd /tmp
lcd /etc
put issue
!sleep 10
put motd
bye

$ sftp -b batchfile username@hostname

I tried that, but I need to handle multiple, unique filenames. In your example, how would you handle sending three files named issue8, issue23 and issue989 if you had to send them separately, sleeping for a given time in between each?

I can't pass the filenames from my script to the sFTP batchfile using variables or any "for filename in" construct. Once you pass control off to the sFTP batchfile, it only understands sFTP commands.
# 6  
Old 07-02-2007
I ran into the same problem.. i needed to pass variables to the sftp batch..

As a "solution" i found this:
Code:
touch sftp_batch
for files in `ls -1 /dir` ; do
{
echo "get $files" >> sftp_batch
}
echo "quit" >> sftp_batch

sftp -b sftp_batch $server  2> errors

rm sftp_batch

so basicly, i create the whole batch on the fly...
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

SFTP batch not renaming file with "put"

I have a .ksh script that creates an sftp batch file and runs it through sftp. It works except for one thing. If I try to "put" to a different name, it doesn't use the specified remote name...it still "puts" the original local name. I've tried both of these, and neither work...it will always... (4 Replies)
Discussion started by: dbiggied
4 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

Scripting to fix the issue in UNIX file having delimiter "|"

hello All, I am new user to shell scripting, kindly advise on the below? I have a file where i have gaps & the delimiter falls in next line and new line is also created , plz see the example :employee.txt Now the issue here is , i wan to write a script , where i can use "|" to get the... (6 Replies)
Discussion started by: sunnyd1
6 Replies

5. Shell Programming and Scripting

AWK for multiple line records RS="^" FS="#"

I have to pull multiple line records with ^ as the record separator(RS)... # should be my field separator (FS)... Sample record is: ^-60#ORA-00060: deadlock detected while waiting for resource ORA-00001: unique constraint (SARADM.TCKNUM_PK) violated#PROC:AVAILABLE_FOR_GETNXTTIC#02/27/2012... (7 Replies)
Discussion started by: Vidhyaprakash
7 Replies

6. Shell Programming and Scripting

How to Write sftp through "expect" for file upload ?

Hi Experts , I am new to unix programming please tell me how to write expect and hoe to call it for automated file upload process. help me really ! (0 Replies)
Discussion started by: kulbhushan
0 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

sftp can't fine batchfile "No such file or directory"

Hi, I've got a C program that is using execlp to run a non-interactive sftp (using a batchfile) session to send some files to another system. Just before doing that, I create the batchfile called sftp_batch on the fly: V8_26_1:sun-->cat /workspace/sftp_batch cd /tmp/newsftp put test.file... (2 Replies)
Discussion started by: Fiaran
2 Replies
Login or Register to Ask a Question