Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
With that out of the way, if you are automating SFTP transfers then you need to be using batch mode, and that has key-based authentication as a prerequisite. Certificates would work as well. You can specify the key (or a certificate instead) using the -i option and the batch script using the -b option. The script may be read either from stdin or from a file. Here is an example using stdin and a Here Document:
Code:
date=$(date +"%Y%m%d")
cat <<EOS | sftp -b - \
-i /path/to/your/sshkeys/synerg_ed25519_key \
(username)@server.example.com
cd /Home/nni_mktbi_synergistix/Samples/Synergistix/
lcd /opt/infa_shared/icm/Infa_Adm/TgtFiles/
get $date
EOS
Or you can put the SFTP commands in a file and read that instead of "-"
Last edited by Turbocapitalist; 07-12-2019 at 02:44 AM.
Reason: sanitized example
sftp> can't read "DATE": no such variable
while executing
"send "get $DATE \r""
Please resolve. Tried other forums for solution but its not working!!
Since this is YOUR task, it's fairly rude of you to tell us to resolve it for you, especially since you say you've posted this on other forums too. And we certainly aren't going to call or email you personally with solutions...if you'd like one-on-one tech support, I'm sure there are lots of people who would be willing to provide that. Just tell us how much you're going to pay to have someone else perform your tasks for you.
Past that, if you're using SFTP, consider NOT using expect, since there's no need. Perform an SSH keyswap between the two systems, and eliminate the need to hard code a user ID and password into a script (which is VERY BAD from a security standpoint). Leaving you with something like:
As others have said you can use sftp batch mode to accomplish this. Use of expect is good for interactive sessions such as telnet where you have to login, wait for a prompt, enter something, wait for another prompt, etc... Most file transfer protocols don't need it. Even with old fashioned ftp you could use "here document" coding and avoid expect.
Ideally for sftp you'd set up a trust wherein you send the public key from originating user/system to be imported into the authorized_keys of the destination user/system so wouldn't need the password.
If you absolutely have to use the password you could use sshpass. It may not already be installed so you might have to install it.
Novo Nordisk is a pharmaceutical company and conduit.novonordisk-us.com appears to be a portal to upload and download files. While suggesting using keys is a good idea it has nothing to do with the question. In addition we do not know anything about the website or what software is running so keys or scp may not be applicable.
Novo Nordisk is a pharmaceutical company and conduit.novonordisk-us.com appears to be a portal to upload and download files. While suggesting using keys or sshpass is a good idea it has nothing to do with the question. In addition we do not know anything about the website or what software is running so keys or scp may not be applicable.
This post mystifies me. The OP clearly shows the expect script is doing sftp:
Code:
spawn sftp (username)@conduit.novonordisk-us.com
Keys are definitely germane to the discussion and sshpass is a viable tool to read in passwords with sftp (which lives on the ssh ecosystem) if the partner doesn't agree to use keys.
My organization does quite a bit of B2B here using various protocols and our preference is always sftp with keys. If we can't get the partner to use keys we use sshpass. If we absolutely have to we use lftp to do ftps (not sftp) or even "here documents" for the few remaining partners that still do ftp (not ftps or sftp) even though it is a security risk. We could talk about http/https get and post or AS2 as well but as noted above the OP is using sftp.
Last edited by MensaWater; 07-12-2019 at 03:06 PM.
I did not say that anything was wrong with keys except that we do not know if the OP can use them. Sorry, I messed up my post and did not mean to suggest that sshpass was not a good solution and using it with batch mode in post #2 might be the OP easiest solution.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.