Solved

Correct syntax to upload file in a script using sftp

Posted on 2016-08-22
2
61 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
Comment Utility
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
Comment Utility
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 sshd & ssh-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

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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 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…
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.

762 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

6 Experts available now in Live!

Get 1:1 Help Now