Solved

sftp client authentication methods

Posted on 2009-05-04
9
657 Views
Last Modified: 2013-12-09
I'm trying to connect to an sftp server, but am unable to do so through a bash script.  the server is expecting ssh key authentication by default and i'd like to do UserName/Password auth.  Is there a way i can specify the type of auth i want to use and if so what are some examples?  Such as:
sftp -oAuthenticationMethod=Password MyName@ftp.ExampleServer.com
or
sftp -oAuthenticationMethod=SSH_KEY MyName@ftp.ExampleServer.com

I've tried using the -o options, but am not sure i got the syntax right.
also, i interactivly try and connect to the sftp server it will prompt me for a password and when i enter it, it's just fine.
i'm running the bash script on Linux machine which is trying to connect to a sftp server running on windows machine.
0
Comment
Question by:nohurt
  • 3
  • 3
  • 3
9 Comments
 
LVL 7

Assisted Solution

by:mchkorg
mchkorg earned 130 total points
ID: 24302287
Just to be sure: you're not confused between sftp and ftps ?
- sftp is "FTP over SSH", it requires a SSH server
- ftps is "secured FTP", it requires a FTP server with SSL

What's your server software on Windows ?
0
 
LVL 28

Assisted Solution

by:lesouef
lesouef earned 120 total points
ID: 24305005
the only I know to overcome this (avoid the interactive questions) is to use an answer file with the commands in it, as argument to ftp-s filename,
or use a .netrc file in your account root folder to store the account defaults
0
 

Author Comment

by:nohurt
ID: 24307015
i'mtrying to connect to a partner who is hosting the sftp server on windows.  i'm not sure what server they are running.  they have asked that i connect to them using "sftp UserName@sftp.PartnerName.com".  When i do that interactively from command line on a linux box, the sftp server prompts me for my password, i enter it and all is fine.  When i try and connect using (through a bash script):
expect << 'END' 2>&1 | tee -a $LogFile
set timeout 5
spawn sftp $env(UserID)@$env(HostToConnectTo)
expect "UserName@ftp.PartnerName.com's password: "
send -- "$env(Password) \r"
expect "sftp> "
send -- "cd $env(OutPutDir) \r"
expect "sftp> "
send -- "ls -l ../ \r"
expect "sftp> "
send "bye \r"
END
 
The partner has not "White listed" my ssh key on their server, so it doesn't work.  I would like to know if there is an option for sftp so that i can be very specific on sftp command line the use of authentication (password or ssh key).
0
 
LVL 28

Assisted Solution

by:lesouef
lesouef earned 120 total points
ID: 24307229
have you tried the old URL method:
sftp user:passwd@site.com
or removing the password: mention, entering the password strait away after the login line? (I do that on ftp)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 28

Assisted Solution

by:lesouef
lesouef earned 120 total points
ID: 24310611
foud this also:
sftp [-1vC] [-A Password] [-b batchfile] [-L logfilename] [-osshopt=value] [user@]host[:file [file]]

The host must be given on the command line. The current interactive username will be used unless a user id is passed on the command line. This is done by adding the desired username to the hostname with the @ symbol. For example to connect to sftpserver as administrator, connect with

sftp administrator@sftpserver

OPTIONS

1
 use the SSH1 protocol
 
v
 verbose mode for debugging
 
C
 use compression
 
A Password
 use password to logon to sftp server
 
b batchfile
 automation file - list desired commands to process after connected
 
L logfilename
 allows commands and responses to be logged to file logfilename
 
o sshoptions
 ssh client options
0
 
LVL 7

Accepted Solution

by:
mchkorg earned 130 total points
ID: 24311607
If keyauthentication is enabled, it should work without asking anything.
Maybe try with scp. Sftp should be used as a ftp client, I mean : browsing directories and so on.
If you just want to transfer files over SSH, scp sound better:

scp user@host:/some/file some_local_destination

OR

scp something_local user@host:/something

You can use "-r" for recurse and so on


AND: are you sure you public key is in the authorized_keys on server's side? If not, you might add it manually in a regular ssh session.
0
 

Author Comment

by:nohurt
ID: 24382278
my authorized_key is in the file. If i "sftp username@server.com" i get in just fine and am at the sftp> prompt.  But if i try and ssh or scp a file, it just hangs.  i'm not sure what's going on.
0
 
LVL 7

Assisted Solution

by:mchkorg
mchkorg earned 130 total points
ID: 24382844
authorized_key => authorized_keys

Please, copy/paste the ssh and scp command you enter
0
 

Author Closing Comment

by:nohurt
ID: 31577899
it turns out that the ftp server i connect to has to accept my ssh key on their side manally in the sftp server.  i am not allowed to put a public ssh key on their server.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Outsource Your Fax Infrastructure to the Cloud (And come out looking like an IT Hero!) Relative to the many demands on today’s IT teams, spending capital, time and resources to maintain physical fax servers and infrastructure is not a high priority.
When the confidentiality and security of your data is a must, trust the highly encrypted cloud fax portfolio used by 12 million businesses worldwide, including nearly half of the Fortune 500.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now