2012-12-11 77 views
3

我想通过FTP访问远程服务器上的GIT存储库。由于某些不幸的原因,服务器只允许主动模式FTP而不是被动模式。即如果我用卷曲(由git clone使用同一个客户端)直接下载一个文件,下面的命令作品:在git-clone期间使用主动模式FTP而不是被动模式?

curl -P - ftp://user:[email protected]/file 

但服用-P -出来会造成卷曲挂起,直到超时。

问题是我不知道如何告诉git clone使用主动模式的FTP。当我设置GIT_CURL_VERBOSE=1并做了git clone ftp://user:[email protected]/repo,我注意到它发送的是PASV而不是PORT,并且挂起时就像没有使用-P -开关的卷曲一样。我如何告诉它做其他事情?我读了一些关于_netrc的文件,但找不到通过它设置活动模式的示例。

对于任何好奇,这里是从git clone冗长卷曲输出(几乎一样运行curl不指定-P -选项。)

* About to connect() to server.com port 21 (#0) 
* Trying {server ip}... * 0x98d548 is at send pipe head! 
* Connected to server.com ({server ip}) port 21 (#0) 
< 220 Microsoft FTP Service 
> USER User 
< 331 Password required for User. 
> PASS {pass} 
< 230 User User logged in. 
> PWD 
< 257 "/User" is current directory. 
* Entry path is '/User' 
> CWD repo.git 
< 250 CWD command successful. 
> CWD info 
< 250 CWD command successful. 
> EPSV 
* Connect data stream passively 
< 500 'EPSV': command not understood 
* disabling EPSV usage 
> PASV 
< 227 Entering Passive Mode ({server ip},10,137). 
* Trying {server ip}... * Connecting to {server ip} ({server ip}) port 2697 
/* server hangs from here until time-out */ 

随着卷曲指定的-P -选项,PORT命令将代替使用PASV,因此从EPSV线下面的命令将被发送,而不是向服务器开始:

> EPRT |1|{client ip}|13375| 
< 500 'EPRT |1|{client public ip}|36093|': command not understood 
* disabling EPRT usage 
> PORT {client ip},52,64 
< 200 PORT command successful. 
* Connect data stream actively 
> TYPE I 
< 200 Type set to I. 
> SIZE file 
< 213 213 
> RETR file 
< 150 Opening BINARY mode data connection for file(213 bytes). 
/* and the file just downloads from here. */ 

我的配置:msysgit,MS-FTP服务器。

+0

服务器是否支持EPSV模式? – CharlesB

+0

不,它不。 'EPSV'实际上是在回退到'PASV'之前尝试的第一个命令'git clone'。 – ydyu

+0

你有什么想法,为什么它挂着git,而不是'curl -P'? – CharlesB

回答

1

的Git实际上deprecated FTP这样的困难,可能是因为,:

的Git支持SSH,git的,HTTP和HTTPS协议(另外,FTP, 和FTPS,可用于获取和可使用的rsync用于获取 并推送,但这些效率不高并且不推荐使用;不要使用 他们)。

最好的办法是将FTP服务器的远程repo同步到本地裸露克隆,并将其重新克隆到工作副本。

+1

非常感谢!我实际上设法找到一个开放的端口来启用服务器上的PASV模式。但是通过阅读这个,最好的答案可能确实是“尽量不要使用FTP”。我会研究其他选项。 – ydyu