LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-02-2015, 08:36 AM   #1
jbirdmotox
LQ Newbie
 
Registered: Nov 2015
Posts: 2

Rep: Reputation: Disabled
SCP or SFTP files in a loop


Hello,
I'm trying to simplify the following script. In a perfect world I would like to have the SOURCE_FILE and DEST_DIR variables increment automatically. I would also like to use a loop in the delivery.

At this point I would be happy with just a loop in the SCP or SFTP commands. I have scripts that have with 100+ SOURCE_FILE's all going to diff DEST_DIR's. Just trying to cut down on the manual maintenance of these things.

Thanks in advance for any help pointing me in the right direction,
Jon


##### SPECIFY LOCAL SOURCE LOCATION OF THE FILES #####
SOURCE_DIR1=/opt/xxxxxxx/middleware/scheduled_extracts/data

##### SPECIFY FILES TO BE DELIVERED #####
SOURCE_FILE1=test.txt
SOURCE_FILE2=test2.txt

##### SPECIFY DESTINATION FOLDER FILES TO BE DELIVERED TO ######
DEST_DIR1=/FileDrop/non-encrypted/Report_A
DEST_DIR2=/FileDrop/non-encrypted/Report_B

##### MAKE CONNECTION TO FILEDROP SERVER #########
sftp -b /dev/stdin user_sftp_test@vmpit-xxxx.yyyy.com <<END_SCRIPT

##### CHANGE TO SOURCE DIRECTORY OF FILES ####
lcd $SOURCE_DIR1

##### CHANGE TO DESTINATION FOLDERS AND PUT THE FILES #####
cd $DEST_DIR1
-put $SOURCE_FILE1
cd $DEST_DIR2
-put $SOURCE_FILE2
bye
END_SCRIPT
 
Old 11-02-2015, 08:50 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
i think that scp is useful for machines and sftp is useful for humans.

what i normally do is something like this:
Code:
[schneidz@hyper ~]$ cat list-of-files.txt
./hack.ksh schneidz@xbmc:Music
./hack2.ksh schneidz@xbmc:Videos
[schneidz@hyper ~]$ cat list-of-files.txt | while read line
do
 scp $line
done
 
Old 11-02-2015, 09:06 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Personally I always use scp in both cases; the syntax is so much simpler.
(ok, if I'm on MSWin and using Filezilla, it uses sftp in the background...)
 
Old 11-03-2015, 09:54 AM   #4
jbirdmotox
LQ Newbie
 
Registered: Nov 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by chrism01 View Post
Personally I always use scp in both cases; the syntax is so much simpler.
(ok, if I'm on MSWin and using Filezilla, it uses sftp in the background...)
Thanks for the suggestions. I have been playing around with scp and a txt file.

Jon
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
scp vs. sftp Holyninja Linux - Newbie 1 10-29-2007 06:28 PM
allow ssh, scp and sftp? javier_ccs Linux - Newbie 6 09-12-2006 08:11 AM
SCP/SFTP problem tpe Linux - Security 3 03-12-2005 06:58 PM
scp/sftp over lan slow/stalled with larger files m29389 Linux - Networking 2 06-24-2004 04:03 AM
scp vs. sftp . . . zthomasz Linux - Security 2 07-08-2003 08:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration