Solved

Correct syntax to upload file in a script using sftp

Posted on 2016-08-22
2
97 Views
Last Modified: 2016-08-31
I just had a vendor change their server from ftp to sftp.
I was using the following code in my script:
ftp -in $HOST <<- EOF
    user $USER $PASS

But was told this wouldn't work anymore since I now have to connect using the sftp command.
Can someone let me know what the proper syntax I need to use in order to upload a file to a sftp server.
0
Comment
Question by:metalteck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Assisted Solution

by:Hanno P.S.
Hanno P.S. earned 250 total points
ID: 41766641
If you have to use sftp it looks like you will be using ssh to transfer files.
Maybe, using scp (Secure CoPy) instead would be much easier.

Anyway, to use sftp the syntax would be something like:
sftp sourcefile user@host:targetfile
see: man sftp

For non-interactive use scp should be used instead:
scp sourcefile user@host:targetfile

If you use secret keys for authentivcation, no password will be needed anymore.
1
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 250 total points
ID: 41767926
According to my copy of the man page, to send files from a script you need to use
sftp -b batchfile [user@]host
You must configure non-interactive authentication before using sftp -b. The man page refers you to sshdssh-keygen for instructions.
The format would then be along the lines of
sftp -b - ${USER}@${HOST} <<////
put ${file_to_go}
qui
////

Open in new window

The curly brackets may or may not be necessary.
I always use a four-slash terminator (don't ask ...)
1

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

726 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