• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with FTPClient

 
marco tognoni
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use this code:
import java.net.*;
import java.io.*;
import java.security.*;
import alibo.net.www.protocol.ftp.FtpURLConnection;
public class ProvaFtp {
public static void main(String args[])
{
System.getProperties().put( "http.proxySet","true");
System.getProperties().put( "http.proxyHost", "proxysar.saritel.it" );
System.getProperties().put( "http.proxyPort", "8080" );
System.getProperties().put( "ftp.ProxySet", "true" );
System.getProperties().put( "ftp.ProxyHost", "proxysar.saritel.it" );
System.getProperties().put( "ftp.ProxyPort", "8080" );
System.getProperties().put( "ftpProxySet", "true" );
System.getProperties().put( "ftpProxyHost", "proxysar.saritel.it" );
System.getProperties().put( "ftpProxyPort", "8080" );

try {
URL url=new URL(args[0]);
String protocol=url.getProtocol();
System.out.println(protocol);
if(protocol.compareTo("ftp")==0)
{
FtpURLConnection connection=new FtpURLConnection(url);
InputStream is=connection.getInputStream();
}
else
{
URLConnection connection=url.openConnection();
Permission allow=connection.getPermission();

if(allow!=null)
System.out.println(allow);

InputStream is=connection.getInputStream();
}

} catch(Exception e) {
e.printStackTrace();
}
}
}
it goes error like this:
java.net.NoRouteToHostException: No route to host: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:295)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:161)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148)
at java.net.Socket.connect(Socket.java:425)
at java.net.Socket.connect(Socket.java:375)
at java.net.Socket.<init>(Socket.java:290)
at java.net.Socket.<init>(Socket.java:118)
at alibo.net.NetworkClient.doConnect(NetworkClient.java:51)
at alibo.net.NetworkClient.openServer(NetworkClient.java:39)
at alibo.net.ftp.FtpClient.openServer(FtpClient.java:269)
at alibo.net.ftp.FtpClient.<init>(FtpClient.java:389)
at alibo.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.
java:84)
at alibo.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConn
ection.java:103)
at ProvaFtp.main(ProvaFtp.java:26)

why can't it find the host if I use proxy server ?
tell me something,
thanks a lot,
mauro
 
Jon Dornback
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look at the error stack trace. the last line is:
"at ProvaFtp.main(ProvaFtp.java:26)"
so then, assuming there is a space at the top of your program before the import statements, that makes this line 26:
FtpURLConnection connection=new FtpURLConnection(url);
now, look above where the variable url is defined:
URL url=new URL(args[0]);
args[0] is the first argument on the command line. so even though you declared a proxy server property, you are trying to connect to whatever you type in from the command line. (example: java ProvaFtp 127.0.0.1) so if you don't have any arguments on the commandline, you are trying to connect to a null host string. check to see if that's the problem, and send an update on what you find.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!