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
Solved

FTP through proxy

Posted on 2001-08-28
4
982 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet  URL Rewriting 1 42
Groovy problem when using SOAPUI : DispatchException occurred 7 58
going to wrong jsp page 2 33
Tagging and Merging on Branch 1 29
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

840 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