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?
Yves AccadConnect With a Mentor Network 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.
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.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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:'
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...
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.