[英]Connecting to an FTP server via a proxy using Apache FTPClient
Using the Apache FTPClient, i can usually connect using the following statements: 使用Apache FTPClient,我通常可以使用以下语句进行连接:
FTPClient client = new FTPClient();
client.connect("ftp.myhost.com");
client.login("myUsername", "myPassword");
client.changeWorkingDirectory("/fileFeed");
client.setFileType(FTPClient.BINARY_FILE_TYPE);
client.setFileTransferMode(FTPClient.BLOCK_TRANSFER_MODE);
The above works fine but now i am to connect to the FTP site, i have to use a proxy server. 以上工作正常,但现在我要连接到FTP站点,我必须使用代理服务器。 The instructions i got is that i should connect to the proxy server and specify the actual ftp server in the username.
我得到的指示是我应该连接到代理服务器并在用户名中指定实际的ftp服务器。 So to log on i would use the following details to connect:
因此,要登录,我将使用以下详细信息进行连接:
ftp ftp.myProxyServer.com
username myUsername@ftp.myhost.com
password myPassword
I tried connecting directly using the command prompt and i can connect to the ftp.myProxyServer.com host and it does forward me to the intended ftp site if i specify myUsername@ftp.myhost.com as the host username. 我尝试使用命令提示符直接连接,我可以连接到ftp.myProxyServer.com主机,如果我指定myUsername@ftp.myhost.com作为主机用户名,它会将我转发到预期的ftp站点。 The problem is that the above type of connection is not accepted in Java using Apache FTPClient:
问题是使用Apache FTPClient在Java中不接受上述类型的连接:
FTPClient client = new FTPClient();
client.connect("ftp.myProxyServer.com");
client.login("myUsername@ftp.myhost.com", "myPassword");
client.changeWorkingDirectory("/fileFeed");
client.setFileType(FTPClient.BINARY_FILE_TYPE);
client.setFileTransferMode(FTPClient.BLOCK_TRANSFER_MODE);
Is there anything i am missing or would the above not work? 我有什么遗失或上述不起作用吗? I tried a direct connection and that works fine.
我尝试了直接连接,并且工作正常。
The FTPClient usually is in active ftp mode, and in case your proxy is not able to initiate a tcp connection back to your client computer (for firewall/DMZ reasons) then you have to switch to passive mode: FTPClient通常处于活动的 ftp模式,如果您的代理无法启动tcp连接回客户端计算机(出于防火墙/ DMZ原因),则必须切换到被动模式:
FTPClient client = new FTPClient();
client.connect("ftp.myProxyServer.com");
client.login("myUsername@ftp.myhost.com", "myPassword");
client.enterLocalPassiveMode(); //switch from active to passive
client.changeWorkingDirectory("/fileFeed");
...
(Furthermore I would like to recommend to always check the return codes of the method calls, but probably they are ommitted for sake of clarity) (此外,我建议始终检查方法调用的返回码,但为了清楚起见,可能会省略它们)
Sorry for the late attempt to answer your question... 对于迟到的尝试回答你的问题感到抱歉......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.