Solved

Correct syntax to upload file in a script using sftp

Posted on 2016-08-22
2
81 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
2 Comments
 
LVL 16

Assisted Solution

by:Hanno Schröder
Hanno Schröder 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

776 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