4

I have a git repo set on a remote server. I'm trying to clone it on my own PC with this command :

git clone ftp://x.x.x.x/testGit/ testGit

But I keep getting the error :

fatal: unable to access 'ftp://x.x.x.x/testGit/': Server denied you to change to the given directory

The same URL works fine in my browser, I don't really understand ...

I'm using vsftpd with this config :

listen=YES
anonymous_enable=YES
local_enable=NO
write_enable=NO
local_root=/home/play/

I'm out of ideas ...

Zenoo
  • 12,670
  • 4
  • 45
  • 69
  • is that git repo listening on ftp port? Whenever i clone from github or bitbucket its always http or https for the protocol. – victor Jun 13 '17 at 14:24
  • What do you mean "listening on ftp port" ? I'm accessing the repo via a FTP protocol, is there an option to tweak in git for that? – Zenoo Jun 13 '17 at 14:29

2 Answers2

4

You need to run git update-server-info on the server :)

If the repository is non-bare (i.e. has a .git directory), you also need to append /.git to the path as mentioned by @Rohit Pothuraju.


How do you debug problems like this?

My first attempt was to to get a verbose log out of vsftpd. I read the manual and set the relevant options, but it didn't work (the log was empty).

So I fell back to intercepting the TCP connection. The most primitive way to do that is have three terminal windows running the following commands:

1. nc -v x.x.x.x 21     # connect to the real server
2. nc -l -v -p 1234     # listen on some port
   # if it says "This is nc from the netcat-openbsd package", remove the '-p'
3. git clone ftp://localhost:1234/testGit/ testGit
   # the program you want to debug, but with the server address replaced

Now you'll see messages from the server in Terminal 1 and messages from the program in Terminal 2. When you see a message in one terminal, copy it and paste it into the other terminal. Keep going until the session ends.

Tips:

  • The -v flag causes netcat to print one or two debugging lines. Make sure you don't copy them between the two terminals! In Terminal 1 this should be similar to

    localhost [123.0.01] (?) open
    

    and in Terminal 2 it should be similar to

    listening on [any] 1234...
    connect to [127.0.0.1] from localhost [1237.0.0.1] 53929
    
  • With some protocols (such as FTP) the server sends the first message. Don't forget to copy that message over once the program connects, otherwise it will wait forever.

tom
  • 21,844
  • 6
  • 43
  • 36
  • Thanks for looking into it ! I tried `git update-server-info`, it didn't say anything and it still didn't work when I tried to clone the repo. Then I tried the `netcat` thingie, but the problem is, if I understood correctly, I have to open those terminals on my own PC, not on the server, right? If so, i'm on Windows and I don't have the `netcat` command. – Zenoo Jun 16 '17 at 08:59
  • @Zenoo: Damn, I was sure that was the problem. The command `git update-server-info` creates the files *info/refs* and *objects/info/packs* in the git directory. Can you open `ftp://x.x.x.x/testGit/info` in a web browser and check that *refs* exists and has some content? – tom Jun 17 '17 at 02:50
  • @Zenoo: My description of the netcat interception is indeed for running on the local PC, but you can also do it on the server if you have SSH access and the server is not firewalled. Run commands 1 and 2 on the server using two SSH sessions instead of locally on your PC. In command 1, replace `x.x.x.x` with `localhost`. In command 3, replace `localhost` with `x.x.x.x`. If you get connection errors when you run command 3 you'll need to use SSH port forwarding. Let me know. – tom Jun 17 '17 at 03:06
  • There is indeed an `info` folder inside the `.git`. inside `refs`, there are `heads` and `tags` folders. I'll try the netstat via SSH now – Zenoo Jun 19 '17 at 07:13
  • I'm getting this error when I try to setup the second terminal : `This is nc from the netcat-openbsd package. An alternative nc is available in the netcat-traditional package. usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port] [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [hostname] [port[s]] `. I'm guessing I'm using the `nc` command wrong, but I can't really figure out why. – Zenoo Jun 19 '17 at 07:18
  • @Zenoo: There are several files/directories with the same name in different places, it's a bit confusing. Assuming the git directory is `testGit/.git`, I am talking about the file `testGit/.git/info/refs` (on the server). It should be a plain text file with lines of the form ` refs/heads/`. If the file is missing, try running `git update-server-info` again (on the server). It shouldn't produce output, but it should create that file. – tom Jun 19 '17 at 09:36
  • @Zenoo: There are several incompatible versions of `netcat`. The version you have needs to be used without the `-p` argument. I mentioned it in my answer, but not clearly enough. I'll update the answer. – tom Jun 19 '17 at 09:42
  • It's asking me for authentification even though I'm in anonymous mode ... Here are the terminals if you want more info : https://zenoo.tinytake.com/media/568774?filename=1497866938406_19-06-2017-12-08-53.png&&type=attachment&&&_felix_session_id=dec2d9a9b31e9860f61ac7b030392104&salt=MTcwNjcyM181NjcwNzcy – Zenoo Jun 19 '17 at 10:09
  • Let's continue the discussion in [chat](https://chat.stackoverflow.com/rooms/147063/https-stackoverflow-com-questions-44524251). – tom Jun 19 '17 at 11:58
0

I suggest you try this..

git clone ftp://username:password@ftp.company.com:PORT/project.repo/.git

It might work....