Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-11-2011, 01:10 AM   #1
LQ Newbie
Registered: Oct 2011
Posts: 7

Rep: Reputation: Disabled
Getting files form sftp using script!!!

Hi! need to get *.csv files from sftp on a particular schedule. i need to do that using script. as i'm new to shell scripting don't know much. can anyone help me out with a script which will connect to sftp.. get *.csv files from there to local server.

Thanks alot....
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 11-11-2011, 01:28 AM   #2
Registered: Apr 2010
Posts: 83

Rep: Reputation: 32
Without knowing much detail ...


scp user@host:/path/to/file.csv /path/to/local/directory/
Old 11-11-2011, 01:37 AM   #3
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Do you want to get all *.csv files from an sftp server, or particular ones?

The easiest way is to use public key authentication, with ssh-agent, and use ssh-add to save the passphrase for your private key. Then you can simply use a batch file to retrieve the .csv files.

eval $(ssh-agent)
ssh -b ftpscript user@host
I tried this out just now on my laptop. The ssh server is my desktop. I did it for ogg instead of csv files because I had ogg files on my desktop.
The script was
mget *.ogg
For unattended cron jobs, you may need to use a private key without a passphrase. The passphrase protects the private key on the client, not on the sftp server. The server has a copy of your public key.

Here is another example. Given how simple the request is, I supplied the batch command on the fly:
sftp -b  <(echo 'mget *.ogg') elite
Use username@host instead of elite. If the user is the same, you only need the hostname.

If you can use the scp program, it would be even simpler.
scp elite:'*.ogg' .

Last edited by jschiwal; 11-11-2011 at 01:41 AM.
2 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Batch files to execute and transfer files via sftp cm67 Linux - General 5 08-13-2009 09:59 AM
sftp script help imkornhulio Programming 11 09-17-2008 11:23 AM
SFTP Script chnlinux Linux - Newbie 2 09-28-2007 03:53 PM
shell script works form command line but not form crontab saifee General 1 10-14-2004 10:27 AM
Files truncated by sftp/sftp-server at 65kb gato Linux - Networking 1 12-18-2003 10:29 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:37 PM.

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