Solved

FTP through proxy

Posted on 2001-08-28
4
971 Views
Last Modified: 2008-02-01
I'm trying to ftp (using Suns nonstandard ftp class) through our proxy server and I've been able to get through it and can "cd" etc.
The problem comes when it actually comes to 'get'ing the file.

I consistantly get the following exception.
++++++
Exception in thread "main" sun.net.ftp.FtpProtocolException: RETR drop.sql
        at sun.net.ftp.FtpClient.openDataConnection(FtpClient.java:224)
        at sun.net.ftp.FtpClient.get(FtpClient.java:315)
        at maltest.main(maltest.java:30)
++++++++

The file exists and is owned by the logged in owner.
Any ideas?

My java source is below...

Cheers,

Mal

++++++++


import java.io.*;
import java.net.*;
import java.util.*;
import sun.net.ftp.FtpClient;

public class maltest {

    public static void main(String args[]) throws Exception {

    String host = "mydomain.co.uk";
    String path = "/home/drop.sql";
    String username = "user";
    String password = "password";

    int lastSlash = path.lastIndexOf('/');
    String filename = path.substring(lastSlash+1);
    String directory = path.substring(0,lastSlash);

    System.getProperties().put( "ftpProxySet", "true" );
    System.getProperties().put( "ftpProxyHost", "172.16.2.77" );
    System.getProperties().put( "ftpProxyPort", "8000" );

    FtpClient client = new FtpClient(host);
    client.login(username, password);
    client.ascii();
    client.cd(directory);
    client.cd(directory);


    InputStream is = client.get(filename);
    BufferedInputStream bis = new BufferedInputStream(is);

    OutputStream os = new FileOutputStream(filename);
    BufferedOutputStream bos = new BufferedOutputStream(os);

    byte[] buffer = new byte[1024];
    int readCount;

    System.out.println("Getting: " + filename);
                   
    while( (readCount = bis.read(buffer)) > 0) {
      bos.write(buffer, 0, readCount);
    }
    bos.close();
    System.out.println("done!");

//    client.closeServer();
 

    }

}
0
Comment
Question by:malcx
  • 2
4 Comments
 

Expert Comment

by:lawpan
ID: 6432537
I believe that when the file is sent the FTP server opens a socket to you, trying on port 20. But in that case it tries to connects to your proxy.
You must set your client as PASSIVE. I dont really remember the command or flag for setting you in passive mode.
0
 
LVL 3

Author Comment

by:malcx
ID: 6432761
Thanks but there doesnt seem to be much documentation for this - any idea where I can find this info?

Cheers,

Mal
0
 
LVL 3

Author Comment

by:malcx
ID: 6436463
Cheers for the comment, but I've changed to use an ftp class from:
http://www.enterprisedt.com/downloads/ftp.html

which works fine by just setting the proxy details as before,

once again thanks anyway,
Mal
0
 
LVL 1

Accepted Solution

by:
Moondancer earned 0 total points
ID: 6797602
I have refunded your 100 points to you for this and will close it by moving it to the PAQ, so that the participating expert can be advised, versus deleting it where no further content can be viewed.

Thanks,

Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now