I'm trying to use jenkins to automate an sftp upload and replace so that a folder on a sftp server is equal to the git repository. This is using sftp hosted on an openshift running nginx that only supports ftp using an ssh key which I've already generated using their rhc client. I have been able to connect easily to sftp using filezilla using instructions on https://blog.openshift.com/using-filezilla-and-sftp-on-windows-with-openshift/.
I found the most useful and time efficiency would be using a tool called git-ftp.
The steps are pretty forward for ftp using a username, password, and ftp server domain. I'm struggling getting it to do sftp using my ssh key. Here is a site that I found with the best documentation for commands to use. Reference: http://manpages.ubuntu.com/manpages/trusty/man1/git-ftp.1.html.
I was following this guide to get the Jenkins automation setup https://www.savjee.be/2016/02/Use-Jenkins-and-git-ftp-to-deploy-website-to-shared-webhosting/. However, this doesn't show the command to use sftp.
I used https://tohin.wordpress.com/2014/02/11/git-and-sftp/ to try a few different commands without much luck.
Supposedly this works with ftp only giving username, password, and ftp server:
git ftp init --user USERNAME --passwd PASSWORD ftp://YOUR-FTP-SERVER-ADDRESS/path/to/website/
I've adjusted mine to be:
git ftp init -u <openshiftsshtoken> --sftp-key ~/.ssh/id_rsa sftp://YOUR-FTP-SERVER-ADDRESS/app-root/data/html/<foldertouploadto>
But it's throwing me some errors.
I want to do a git ftp push after initializing it and making sure the sftp works. E.g.
git ftp push -u <openshiftsshtoken> --sftp-key ~/.ssh/id_rsa sftp://YOUR-FTP-SERVER-ADDRESS/app-root/data/html/<foldertouploadto>
Could someone point out the errors that I have?
There have been several issues with using SFTP with Git-ftp in the past. You may face one or several of them.
You need to provide the SSH private key with the --key
option. You are using a different option. Also make sure that you have a public key as well.
SFTP assumes absolute paths on the server by default. If /app-root
is not in your server's root directory, but in your user's home directory, then try the URL sftp://YOUR-FTP-SERVER-ADDRESS/~/app-root/...
. I added ~/
.
And last, if you don't have the server's fingerprint in you known hosts file in the same way as Curl would expect it, then you either need to add it or use the --insecure
flag.
Finally, here as an example from the current manual:
git ftp init -u "john" --key "$HOME/.ssh/id_rsa" "sftp://example.com/~/public_html"