LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-10-2008, 02:03 PM   #1
imkornhulio
Member
 
Registered: Aug 2008
Posts: 58

Rep: Reputation: 15
sftp script help


I need help to write a script which transfers file from my machine to remote host through sftp using shell script.

I know i have to do the put command and specify the directory but don't know the exact syntax on how to put the Username and password automatically...

Last edited by imkornhulio; 09-10-2008 at 02:42 PM.
 
Old 09-10-2008, 02:55 PM   #2
imkornhulio
Member
 
Registered: Aug 2008
Posts: 58

Original Poster
Rep: Reputation: 15
i wrote this script but it does not work

HOST='hostname'
USER='username'
PASSWD='password'

sftp -n ${HOST} << EOF
user {$USER} {$PASSWD}
lcd /home/user/scripts/spuf/
put ben-ip.csv
exit

Last edited by imkornhulio; 09-10-2008 at 03:00 PM.
 
Old 09-10-2008, 03:03 PM   #3
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
How about using scp with pubkey authentication?
 
Old 09-10-2008, 03:19 PM   #4
imkornhulio
Member
 
Registered: Aug 2008
Posts: 58

Original Poster
Rep: Reputation: 15
the host server only allows sftp connection
 
Old 09-10-2008, 03:20 PM   #5
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Any more details on the host server? Is it a scponly shell or something? (If so, I believe both sftp and scp should be allowed.)
 
Old 09-10-2008, 03:28 PM   #6
imkornhulio
Member
 
Registered: Aug 2008
Posts: 58

Original Poster
Rep: Reputation: 15
what would be the script for scp?

syntax
 
Old 09-10-2008, 03:34 PM   #7
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
See the manpages for scp(1).

Basic example:
$ scp /home/me/my-file user@somehost:/secret-dir/
 
Old 09-10-2008, 03:36 PM   #8
imkornhulio
Member
 
Registered: Aug 2008
Posts: 58

Original Poster
Rep: Reputation: 15
What about the password?
 
Old 09-10-2008, 03:38 PM   #9
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Pubkey authentication (with no passphrase). Re-read my first post and use the google.
 
Old 09-17-2008, 09:47 AM   #10
imkornhulio
Member
 
Registered: Aug 2008
Posts: 58

Original Poster
Rep: Reputation: 15
The remote server does not want to use pub and private keys so i'll have to use scp for it

Last edited by imkornhulio; 09-17-2008 at 10:45 AM.
 
Old 09-17-2008, 10:54 AM   #11
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Pubkey authentication is a pretty standard way to automate secure file transfers. If the remote guys aren't being cooperative, you can also look into expect.
 
Old 09-17-2008, 11:23 AM   #12
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by anomie View Post
Pubkey authentication is a pretty standard way to automate secure file transfers. If the remote guys aren't being cooperative, you can also look into expect.
This thread is very similar to another one you have going, isn't it?
 
  


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
SFTP Script chnlinux Linux - General 1 09-28-2007 05:33 PM
SFTP Script chnlinux Linux - Newbie 2 09-28-2007 03:53 PM
Reg the sftp script chnlinux Linux - Newbie 2 09-27-2007 04:27 PM
sftp script via cronjob ?? OzTEXS Linux - Security 21 12-28-2006 03:38 PM
sftp script error JeRrYmAn Linux - Networking 1 11-27-2003 07:21 PM

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

All times are GMT -5. The time now is 02:01 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