LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 11-11-2011, 01:10 AM   #1
nandi
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
jhw
Member
 
Registered: Apr 2010
Posts: 83

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

Code:
#!/bin/sh

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

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.

Example:
Code:
eval $(ssh-agent)
ssh-add
<PASSPHRASE_ENTERED>
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
Code:
mget *.ogg
bye
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:
Code:
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.
Code:
scp elite:'*.ogg' .

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


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:49 AM.

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