简体   繁体   English

使用Apache FTPClient通过代理连接到FTP服务器

[英]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.

相关问题 无法使用 Apache Commons FTPClient 访问 FTP 服务器上的子文件夹 - Can't access subfolders on FTP server using Apache Commons FTPClient 使用apache FTPClient从FTP服务器下载文件 - File Download from a FTP Server using apache FTPClient 使用 Apache Commons Net FTPClient 从 FTP 服务器循环读取多个文件 - Reading multiple files in loop from FTP server using Apache Commons Net FTPClient 使用 Apache FTPClient 使 FTP 服务器返回按时间戳列出的文件 - Make FTP server return files listed by timestamp with Apache FTPClient Apache FTPClient:将文本从 memory 写入 FTP 服务器上的文件 - Apache FTPClient: Write text from memory to file on FTP server 如何使用Java中的FTPClient在FTP服务器中复制文件? - How to copy a file in FTP server using FTPClient in Java? 使用`FTPClient`从FTP服务器下载文件的一部分 - Download part of file from FTP server using `FTPClient` 无法使用Java中的FTPClient在FTP服务器上写入文件 - Could Not Write File on FTP server using FTPClient in Java 使用org.apache.commons.net.ftp.FTPClient从AsyncTask类登录FTP时出错 - Error when logging into FTP from AsyncTask class using org.apache.commons.net.ftp.FTPClient NoRouteToHostException尝试以SFTP模式通过org.apache.commons.net.ftp.FTPClient连接到远程主机 - NoRouteToHostException trying to connect to remote host via org.apache.commons.net.ftp.FTPClient in SFTP mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM