3

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?

lastlink
  • 1,505
  • 2
  • 19
  • 29
  • "But it's throwing me some errors" What errors is it producing? What exactly do they say? Are you able to make an SFTP connection to this remote system using an ordinary sftp client? – Kenster May 15 '17 at 13:22
  • The errors weren't descriptive it was just crashing, I ended up using rsync to handle the task. It is much more efficient and can remove files at target that aren't at the source. – lastlink Aug 03 '17 at 19:28

3 Answers3

4

can you try entering sftp protocol as well as port:22 as

git ftp init --user USERNAME --passwd PASSWORD sftp://domain.com:22/public_html/path/to/website/
alamnaryab
  • 1,480
  • 3
  • 19
  • 31
  • This is THE answer for me. A lot simpler than handling SSH keys, and works too. – johnnydoe82 Oct 22 '21 at 06:30
  • So if you're like me, and didn't read the question, you'll need to do few things. Mileage may vary for some, but for me (on Windows with git-bash installed) in order to get this working I had to go to https://github.com/git-ftp/git-ftp to get the necessary script. Download it, or clone it then `cp` it into /bin/, if there's a more appropriate way let me know. – tisaconundrum Mar 24 '23 at 10:39
4

There have been several issues with using SFTP with Git-ftp in the past. You may face one or several of them.

  1. 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.

  2. 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 ~/.

  3. 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"
maikel
  • 1,669
  • 18
  • 15
1

How about trying the --vv parameter first to show the exact error?

git ftp init -u <openshiftsshtoken> --sftp-key ~/.ssh/id_rsa  sftp://YOUR-FTP-SERVER-ADDRESS/app-root/data/html/<foldertouploadto> -vv
Richard Feraro
  • 467
  • 4
  • 9