当前位置: 技术问答>java相关
如何设计ftp上传程序???
来源: 互联网 发布时间:2014-12-24
本文导语: 我做了一个FTP上传程序(我是通过代理服务器上线的) try { FtpClient client=new FtpClient(); client.openServer(server,21); client.login(user,pass); }catch (IOException e){ out.println(e); } 但是程序返回: java.net.NoRouteToHostException: Host u...
我做了一个FTP上传程序(我是通过代理服务器上线的)
try {
FtpClient client=new FtpClient();
client.openServer(server,21);
client.login(user,pass);
}catch (IOException e){
out.println(e);
}
但是程序返回:
java.net.NoRouteToHostException: Host unreachable: no further information
请指教
谢谢
try {
FtpClient client=new FtpClient();
client.openServer(server,21);
client.login(user,pass);
}catch (IOException e){
out.println(e);
}
但是程序返回:
java.net.NoRouteToHostException: Host unreachable: no further information
请指教
谢谢
|
(COPY)
Connect via socket through a Proxy
You have to set the following properties :
proxySet, proxyHost and proxyPort.
This can be done when starting the JVM for a JAVA application : java -DproxySet=true -DproxyHost=myProxyServer.come -DproxyPort=80 MyJavaApp
Or in your source : import java.util.Properties;
...
Properties systemSettings = System.getProperties();
systemSettings.put("proxySet", "true");
systemSettings.put("proxyHost", "myProxyServer.com");
systemSettings.put("proxyPort", "80");
System.setProperties(systemSettings);
--------------------------------------------------------------------------------
NOTE:
You might need to identify yourself to the proxy server. Use the HTTP property "Proxy-Authorization" with a username:password base64 encoded. Properties systemSettings = System.getProperties();
...
System.setProperties(systemSettings);
URL url=new URL("http://someserver/somepage");
URLConnection uc = url.openConnection ();
String encoded = new String(Base64.base64Encode(new String("username:password").getBytes()));
uc.setRequestProperty("Proxy-Authorization", "Basic " + encoded);
uc.connect();
NOTE: For a base64 function, see this How-to.
--------------------------------------------------------------------------------
In a browser, additionnal settings may be needed. For example with Netscape, you add the following lines in pref.js located in the Netscape user directory. user_pref("security.lower_java_network_security_by_trusting_proxies"), true);
--------------------------------------------------------------------------------
With the JVM included with IE, guess what, proxy properties have different names. Properties propSystem = System.getProperties();
// Sun VM
propSystem.put("proxySet", "true");
propSystem.put("proxyHost", "myProxyServer.com");
propSystem.put("proxyPort", "80");
// Microsoft VM
propSystem.put("firewallSet", "true");
propSystem.put("firewallHost", "myProxyServer.com");
propSystem.put("firewallPort", "80");
propSystem.put("http.proxyHost", "myProxyServer.com");
propSystem.put("http.proxyPort", "80");
Connect via socket through a Proxy
You have to set the following properties :
proxySet, proxyHost and proxyPort.
This can be done when starting the JVM for a JAVA application : java -DproxySet=true -DproxyHost=myProxyServer.come -DproxyPort=80 MyJavaApp
Or in your source : import java.util.Properties;
...
Properties systemSettings = System.getProperties();
systemSettings.put("proxySet", "true");
systemSettings.put("proxyHost", "myProxyServer.com");
systemSettings.put("proxyPort", "80");
System.setProperties(systemSettings);
--------------------------------------------------------------------------------
NOTE:
You might need to identify yourself to the proxy server. Use the HTTP property "Proxy-Authorization" with a username:password base64 encoded. Properties systemSettings = System.getProperties();
...
System.setProperties(systemSettings);
URL url=new URL("http://someserver/somepage");
URLConnection uc = url.openConnection ();
String encoded = new String(Base64.base64Encode(new String("username:password").getBytes()));
uc.setRequestProperty("Proxy-Authorization", "Basic " + encoded);
uc.connect();
NOTE: For a base64 function, see this How-to.
--------------------------------------------------------------------------------
In a browser, additionnal settings may be needed. For example with Netscape, you add the following lines in pref.js located in the Netscape user directory. user_pref("security.lower_java_network_security_by_trusting_proxies"), true);
--------------------------------------------------------------------------------
With the JVM included with IE, guess what, proxy properties have different names. Properties propSystem = System.getProperties();
// Sun VM
propSystem.put("proxySet", "true");
propSystem.put("proxyHost", "myProxyServer.com");
propSystem.put("proxyPort", "80");
// Microsoft VM
propSystem.put("firewallSet", "true");
propSystem.put("firewallHost", "myProxyServer.com");
propSystem.put("firewallPort", "80");
propSystem.put("http.proxyHost", "myProxyServer.com");
propSystem.put("http.proxyPort", "80");
|
代理服务器的PORT提供了对21的转发吗?