Solved

Correct syntax to upload file in a script using sftp

Posted on 2016-08-22
2
118 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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

717 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