?
Solved

FTP through proxy

Posted on 2001-08-28
4
Medium Priority
?
995 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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ā€¦
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationā€¦
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 explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 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