Using cURL and SFTP

Is there a way to modify what I use below to transfer a file automatically but using SFTP?  It is ran from a BASH script.

curl --disable-epsv --ftp-create-dirs -B -T  $LOCALPATH$FILENAME ftp://$USER:$PASS@$FTP/SystemReview/$FILENAME
dwortmanEngineering AssociateAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Yves AccadNetwork Security EngineerCommented:
Something along those lines should work:
curl -k  -u username:password -T filename sftp://IP_Address OR Hostname:/path/to/upload

Open in new window

dwortmanEngineering AssociateAuthor Commented:
Yves Accad,

Based on your comments I created this command:

curl -k  -u username:mypassword -T /tmp/data/df.txt sftp://IPAddress:/SystemReview

But I get an error message saying:

Couldn’t resolve host ‘IPAddress’

I verified that the IP Address I am using is correct.
dwortmanEngineering AssociateAuthor Commented:
I ran it again with the -v switch and got this message:

* getaddrinfo(3) failed for IPAddress:22
* Couldn't resolve host 'IPAddress:'
* Closing connection #0

curl: (6) Couldn't resolve host 'IPAddress:'
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Yves AccadNetwork Security EngineerCommented:
This sounds like you are using 'IPAddress' instead of the Ip address of your SFTP server.  If you're using variables you probably need to refer to it as $IPAddress. But try putting the actual IP without using the variables first to test that it works.

In the example below I use an example IP and this works in my environment:

curl -k  -u username:mypassword -T /tmp/data/df.txt sftp://

Open in new window

dwortmanEngineering AssociateAuthor Commented:
Thanks for the reply.  I do use the numerical IP address but I cannot display it in a public forum (that is what I was told).  For purposes of EE it is an alias like  username and mypassword.
Yves AccadNetwork Security EngineerCommented:
The error message you are receiving indicates that curl is somehow trying to resolve that value, which means it's not seeing it as a numerical IP address but rather as a host name and trying to resolve it. That's why I made the above assumption. What version of curl are you running? I'm using version 7.55.1 and the above command does exactly what you're asking for. Let me know your version and I can dig further.

dwortmanEngineering AssociateAuthor Commented:
I have version 7.21.1

Thanks and have a great weekend...
Yves AccadNetwork Security EngineerCommented:
Thanks have a good weekend too.
I guess I have another obvious question but have to ask nonetheless. Is your server at IPAddress running SSH and accessible on port 22?
You can test by using an ssh client:  
ssh user@IPAddress

Open in new window

. Make sure that works and you can loging to the server you're trying to SFTP to.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dwortmanEngineering AssociateAuthor Commented:

Thanks for the help.  We do not currently have ssh on our client server and this is something that we need to discuss in-house over the next few days.  I am closing this ticket to assign you the points.

Thanks again
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.