Solved

Correct syntax to upload file in a script using sftp

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
aix tls version 6 221
Convert curl speed_dwonload to Mbps 29 99
shell script to send sms 2 88
Need script to search multiple files in one drive 13 35
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
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…
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…

910 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

22 Experts available now in Live!

Get 1:1 Help Now