Solved

FTP through proxy

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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.

728 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