Solved

FTP through proxy

Posted on 2001-08-28
4
985 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

730 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