You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by David Hoffer <dh...@gmail.com> on 2012/10/11 05:27:46 UTC

commons-net sending FTP not working on EC2 server

I just moved an app over to an EC2 server and I'm having trouble
sending data via FTP.  This has worked for years on a different Linux
server, the new one is Linux too just on Amazon EC2.

The code is really simple...basically...

FTPClient ftp = new FTPClient();
ftp.login(username, password);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(fileBytes);
OutputStream os = ftp.storeFileStream(fileName);

byte buf[] = new byte[8192];
int bytesRead = byteArrayInputStream.read(buf);
while (bytesRead != -1) {
       os.write(buf, 0, bytesRead);
       bytesRead = byteArrayInputStream.read(buf);
}
byteArrayInputStream.close();
os.close();
ftp.completePendingCommand();
ftp.logout();

when I debug it...it blocks forever at the call to storeFileStream().
When it runs while not debugging I get a SocketException (Connection
time out)...not sure if at same line or another such as os.write()..

I was using version 3.0.1, I just upgraded to 3.1 to see if that would
help but it has the same problem.  The only difference I can think of
is that the old server was using Java 6 the new one is Java 7.  One
other thing that is different is that the EC2 has most ports blocked,
I've opened port 21 and UDP/DNS.  Is there any other ports that are
needed for FTP?

What might be causing this?  I'm completely stuck not knowing where to
look at this point.

-Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: commons-net sending FTP not working on EC2 server

Posted by sebb <se...@gmail.com>.
On 11 October 2012 09:42, pa7751 <pa...@gmail.com> wrote:
> Hi
>
> I want to do thread pooling on jdk 1.4.

This is nothing to do with NET or ftp.

Please start a new thread for a new subject; and ensure that the
subject line is prefixed with [POOL] - or whatever the component may
be.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: commons-net sending FTP not working on EC2 server

Posted by pa7751 <pa...@gmail.com>.
Hi

I want to do thread pooling on jdk 1.4. I know there is a backport
util that can be used. Can anyone please suggest what is the
difference between backport and apache commons pool v1.5

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: commons-net sending FTP not working on EC2 server

Posted by David Hoffer <dh...@gmail.com>.
I just figured out what the problem was, on the EC2 server I can't use
active mode I suspect because it is sending its local IP address in
the PORT command.  I switched to using passive mode and its working
now.

-Dave

On Thu, Oct 11, 2012 at 7:44 PM, sebb <se...@gmail.com> wrote:
> On 11 October 2012 13:40, David Hoffer <dh...@gmail.com> wrote:
>> This is what I see from the listener.
>>
>> 220 Serv-U FTP Server v12.1 ready...
>> USER *******
>> 331 User name okay, need password.
>> PASS *******
>> 230 User logged in, proceed.
>> PORT 10,144,154,209,143,212
>>
>> What does that PORT line mean?  Is that the incoming ports that must
>> be open?  Why does it use so many ports?  Is that a fixed set or is
>> this configurable?
>
> This is just how FTP handles IP addresses and ports, search for
>
> "FTP PORT command"
>
>> -Dave
>>
>> On Thu, Oct 11, 2012 at 6:13 AM, David Hoffer <dh...@gmail.com> wrote:
>>> Thanks for the reply and info.
>>>
>>> How do I set it in Active mode?  I don't see a method to do this.  I
>>> do see these:
>>>
>>> setActiveExternalIPAddress()
>>> setActivePortRange()
>>>
>>> But those seem to imply they are used if already in active mode...not
>>> clear how to do that.
>>>
>>> I have added the ProtocolCommandListener I'll see what it report.
>>>
>>> Does anyone know what ports must be open for this to work?
>>>
>>> -Dave
>>>
>>> On Thu, Oct 11, 2012 at 2:29 AM, sebb <se...@gmail.com> wrote:
>>>> On 11 October 2012 04:27, David Hoffer <dh...@gmail.com> wrote:
>>>>> I just moved an app over to an EC2 server and I'm having trouble
>>>>> sending data via FTP.  This has worked for years on a different Linux
>>>>> server, the new one is Linux too just on Amazon EC2.
>>>>>
>>>>> The code is really simple...basically...
>>>>>
>>>>> FTPClient ftp = new FTPClient();
>>>>> ftp.login(username, password);
>>>>> ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(fileBytes);
>>>>> OutputStream os = ftp.storeFileStream(fileName);
>>>>>
>>>>> byte buf[] = new byte[8192];
>>>>> int bytesRead = byteArrayInputStream.read(buf);
>>>>> while (bytesRead != -1) {
>>>>>        os.write(buf, 0, bytesRead);
>>>>>        bytesRead = byteArrayInputStream.read(buf);
>>>>> }
>>>>> byteArrayInputStream.close();
>>>>> os.close();
>>>>> ftp.completePendingCommand();
>>>>> ftp.logout();
>>>>>
>>>>> when I debug it...it blocks forever at the call to storeFileStream().
>>>>> When it runs while not debugging I get a SocketException (Connection
>>>>> time out)...not sure if at same line or another such as os.write()..
>>>>>
>>>>> I was using version 3.0.1, I just upgraded to 3.1 to see if that would
>>>>> help but it has the same problem.  The only difference I can think of
>>>>> is that the old server was using Java 6 the new one is Java 7.  One
>>>>> other thing that is different is that the EC2 has most ports blocked,
>>>>> I've opened port 21 and UDP/DNS.  Is there any other ports that are
>>>>> needed for FTP?
>>>>>
>>>>> What might be causing this?  I'm completely stuck not knowing where to
>>>>> look at this point.
>>>>
>>>> Most likely there is a port that is not open.
>>>>
>>>> Try using active FTP mode; that may work better, or may cause issues
>>>> if there is a dumb NAT box in the way.
>>>>
>>>> Try adding a protocol command listener:
>>>>
>>>> ftp.addProtocolCommandListener(new PrintCommandListener(new
>>>> PrintWriter(System.out), true));
>>>>
>>>>> -Dave
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: commons-net sending FTP not working on EC2 server

Posted by sebb <se...@gmail.com>.
On 11 October 2012 13:40, David Hoffer <dh...@gmail.com> wrote:
> This is what I see from the listener.
>
> 220 Serv-U FTP Server v12.1 ready...
> USER *******
> 331 User name okay, need password.
> PASS *******
> 230 User logged in, proceed.
> PORT 10,144,154,209,143,212
>
> What does that PORT line mean?  Is that the incoming ports that must
> be open?  Why does it use so many ports?  Is that a fixed set or is
> this configurable?

This is just how FTP handles IP addresses and ports, search for

"FTP PORT command"

> -Dave
>
> On Thu, Oct 11, 2012 at 6:13 AM, David Hoffer <dh...@gmail.com> wrote:
>> Thanks for the reply and info.
>>
>> How do I set it in Active mode?  I don't see a method to do this.  I
>> do see these:
>>
>> setActiveExternalIPAddress()
>> setActivePortRange()
>>
>> But those seem to imply they are used if already in active mode...not
>> clear how to do that.
>>
>> I have added the ProtocolCommandListener I'll see what it report.
>>
>> Does anyone know what ports must be open for this to work?
>>
>> -Dave
>>
>> On Thu, Oct 11, 2012 at 2:29 AM, sebb <se...@gmail.com> wrote:
>>> On 11 October 2012 04:27, David Hoffer <dh...@gmail.com> wrote:
>>>> I just moved an app over to an EC2 server and I'm having trouble
>>>> sending data via FTP.  This has worked for years on a different Linux
>>>> server, the new one is Linux too just on Amazon EC2.
>>>>
>>>> The code is really simple...basically...
>>>>
>>>> FTPClient ftp = new FTPClient();
>>>> ftp.login(username, password);
>>>> ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(fileBytes);
>>>> OutputStream os = ftp.storeFileStream(fileName);
>>>>
>>>> byte buf[] = new byte[8192];
>>>> int bytesRead = byteArrayInputStream.read(buf);
>>>> while (bytesRead != -1) {
>>>>        os.write(buf, 0, bytesRead);
>>>>        bytesRead = byteArrayInputStream.read(buf);
>>>> }
>>>> byteArrayInputStream.close();
>>>> os.close();
>>>> ftp.completePendingCommand();
>>>> ftp.logout();
>>>>
>>>> when I debug it...it blocks forever at the call to storeFileStream().
>>>> When it runs while not debugging I get a SocketException (Connection
>>>> time out)...not sure if at same line or another such as os.write()..
>>>>
>>>> I was using version 3.0.1, I just upgraded to 3.1 to see if that would
>>>> help but it has the same problem.  The only difference I can think of
>>>> is that the old server was using Java 6 the new one is Java 7.  One
>>>> other thing that is different is that the EC2 has most ports blocked,
>>>> I've opened port 21 and UDP/DNS.  Is there any other ports that are
>>>> needed for FTP?
>>>>
>>>> What might be causing this?  I'm completely stuck not knowing where to
>>>> look at this point.
>>>
>>> Most likely there is a port that is not open.
>>>
>>> Try using active FTP mode; that may work better, or may cause issues
>>> if there is a dumb NAT box in the way.
>>>
>>> Try adding a protocol command listener:
>>>
>>> ftp.addProtocolCommandListener(new PrintCommandListener(new
>>> PrintWriter(System.out), true));
>>>
>>>> -Dave
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: commons-net sending FTP not working on EC2 server

Posted by David Hoffer <dh...@gmail.com>.
This is what I see from the listener.

220 Serv-U FTP Server v12.1 ready...
USER *******
331 User name okay, need password.
PASS *******
230 User logged in, proceed.
PORT 10,144,154,209,143,212

What does that PORT line mean?  Is that the incoming ports that must
be open?  Why does it use so many ports?  Is that a fixed set or is
this configurable?

-Dave

On Thu, Oct 11, 2012 at 6:13 AM, David Hoffer <dh...@gmail.com> wrote:
> Thanks for the reply and info.
>
> How do I set it in Active mode?  I don't see a method to do this.  I
> do see these:
>
> setActiveExternalIPAddress()
> setActivePortRange()
>
> But those seem to imply they are used if already in active mode...not
> clear how to do that.
>
> I have added the ProtocolCommandListener I'll see what it report.
>
> Does anyone know what ports must be open for this to work?
>
> -Dave
>
> On Thu, Oct 11, 2012 at 2:29 AM, sebb <se...@gmail.com> wrote:
>> On 11 October 2012 04:27, David Hoffer <dh...@gmail.com> wrote:
>>> I just moved an app over to an EC2 server and I'm having trouble
>>> sending data via FTP.  This has worked for years on a different Linux
>>> server, the new one is Linux too just on Amazon EC2.
>>>
>>> The code is really simple...basically...
>>>
>>> FTPClient ftp = new FTPClient();
>>> ftp.login(username, password);
>>> ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(fileBytes);
>>> OutputStream os = ftp.storeFileStream(fileName);
>>>
>>> byte buf[] = new byte[8192];
>>> int bytesRead = byteArrayInputStream.read(buf);
>>> while (bytesRead != -1) {
>>>        os.write(buf, 0, bytesRead);
>>>        bytesRead = byteArrayInputStream.read(buf);
>>> }
>>> byteArrayInputStream.close();
>>> os.close();
>>> ftp.completePendingCommand();
>>> ftp.logout();
>>>
>>> when I debug it...it blocks forever at the call to storeFileStream().
>>> When it runs while not debugging I get a SocketException (Connection
>>> time out)...not sure if at same line or another such as os.write()..
>>>
>>> I was using version 3.0.1, I just upgraded to 3.1 to see if that would
>>> help but it has the same problem.  The only difference I can think of
>>> is that the old server was using Java 6 the new one is Java 7.  One
>>> other thing that is different is that the EC2 has most ports blocked,
>>> I've opened port 21 and UDP/DNS.  Is there any other ports that are
>>> needed for FTP?
>>>
>>> What might be causing this?  I'm completely stuck not knowing where to
>>> look at this point.
>>
>> Most likely there is a port that is not open.
>>
>> Try using active FTP mode; that may work better, or may cause issues
>> if there is a dumb NAT box in the way.
>>
>> Try adding a protocol command listener:
>>
>> ftp.addProtocolCommandListener(new PrintCommandListener(new
>> PrintWriter(System.out), true));
>>
>>> -Dave
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: commons-net sending FTP not working on EC2 server

Posted by sebb <se...@gmail.com>.
On 11 October 2012 13:13, David Hoffer <dh...@gmail.com> wrote:
> Thanks for the reply and info.
>
> How do I set it in Active mode?  I don't see a method to do this.  I
> do see these:
>
> setActiveExternalIPAddress()
> setActivePortRange()
>
> But those seem to imply they are used if already in active mode...not
> clear how to do that.

See the example:

http://commons.apache.org/net/examples/ftp/FTPClientExample.java

> I have added the ProtocolCommandListener I'll see what it report.
>
> Does anyone know what ports must be open for this to work?

They are dynamic.

> -Dave
>
> On Thu, Oct 11, 2012 at 2:29 AM, sebb <se...@gmail.com> wrote:
>> On 11 October 2012 04:27, David Hoffer <dh...@gmail.com> wrote:
>>> I just moved an app over to an EC2 server and I'm having trouble
>>> sending data via FTP.  This has worked for years on a different Linux
>>> server, the new one is Linux too just on Amazon EC2.
>>>
>>> The code is really simple...basically...
>>>
>>> FTPClient ftp = new FTPClient();
>>> ftp.login(username, password);
>>> ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(fileBytes);
>>> OutputStream os = ftp.storeFileStream(fileName);
>>>
>>> byte buf[] = new byte[8192];
>>> int bytesRead = byteArrayInputStream.read(buf);
>>> while (bytesRead != -1) {
>>>        os.write(buf, 0, bytesRead);
>>>        bytesRead = byteArrayInputStream.read(buf);
>>> }
>>> byteArrayInputStream.close();
>>> os.close();
>>> ftp.completePendingCommand();
>>> ftp.logout();
>>>
>>> when I debug it...it blocks forever at the call to storeFileStream().
>>> When it runs while not debugging I get a SocketException (Connection
>>> time out)...not sure if at same line or another such as os.write()..
>>>
>>> I was using version 3.0.1, I just upgraded to 3.1 to see if that would
>>> help but it has the same problem.  The only difference I can think of
>>> is that the old server was using Java 6 the new one is Java 7.  One
>>> other thing that is different is that the EC2 has most ports blocked,
>>> I've opened port 21 and UDP/DNS.  Is there any other ports that are
>>> needed for FTP?
>>>
>>> What might be causing this?  I'm completely stuck not knowing where to
>>> look at this point.
>>
>> Most likely there is a port that is not open.
>>
>> Try using active FTP mode; that may work better, or may cause issues
>> if there is a dumb NAT box in the way.
>>
>> Try adding a protocol command listener:
>>
>> ftp.addProtocolCommandListener(new PrintCommandListener(new
>> PrintWriter(System.out), true));
>>
>>> -Dave
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: commons-net sending FTP not working on EC2 server

Posted by David Hoffer <dh...@gmail.com>.
Thanks for the reply and info.

How do I set it in Active mode?  I don't see a method to do this.  I
do see these:

setActiveExternalIPAddress()
setActivePortRange()

But those seem to imply they are used if already in active mode...not
clear how to do that.

I have added the ProtocolCommandListener I'll see what it report.

Does anyone know what ports must be open for this to work?

-Dave

On Thu, Oct 11, 2012 at 2:29 AM, sebb <se...@gmail.com> wrote:
> On 11 October 2012 04:27, David Hoffer <dh...@gmail.com> wrote:
>> I just moved an app over to an EC2 server and I'm having trouble
>> sending data via FTP.  This has worked for years on a different Linux
>> server, the new one is Linux too just on Amazon EC2.
>>
>> The code is really simple...basically...
>>
>> FTPClient ftp = new FTPClient();
>> ftp.login(username, password);
>> ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(fileBytes);
>> OutputStream os = ftp.storeFileStream(fileName);
>>
>> byte buf[] = new byte[8192];
>> int bytesRead = byteArrayInputStream.read(buf);
>> while (bytesRead != -1) {
>>        os.write(buf, 0, bytesRead);
>>        bytesRead = byteArrayInputStream.read(buf);
>> }
>> byteArrayInputStream.close();
>> os.close();
>> ftp.completePendingCommand();
>> ftp.logout();
>>
>> when I debug it...it blocks forever at the call to storeFileStream().
>> When it runs while not debugging I get a SocketException (Connection
>> time out)...not sure if at same line or another such as os.write()..
>>
>> I was using version 3.0.1, I just upgraded to 3.1 to see if that would
>> help but it has the same problem.  The only difference I can think of
>> is that the old server was using Java 6 the new one is Java 7.  One
>> other thing that is different is that the EC2 has most ports blocked,
>> I've opened port 21 and UDP/DNS.  Is there any other ports that are
>> needed for FTP?
>>
>> What might be causing this?  I'm completely stuck not knowing where to
>> look at this point.
>
> Most likely there is a port that is not open.
>
> Try using active FTP mode; that may work better, or may cause issues
> if there is a dumb NAT box in the way.
>
> Try adding a protocol command listener:
>
> ftp.addProtocolCommandListener(new PrintCommandListener(new
> PrintWriter(System.out), true));
>
>> -Dave
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: commons-net sending FTP not working on EC2 server

Posted by sebb <se...@gmail.com>.
On 11 October 2012 04:27, David Hoffer <dh...@gmail.com> wrote:
> I just moved an app over to an EC2 server and I'm having trouble
> sending data via FTP.  This has worked for years on a different Linux
> server, the new one is Linux too just on Amazon EC2.
>
> The code is really simple...basically...
>
> FTPClient ftp = new FTPClient();
> ftp.login(username, password);
> ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(fileBytes);
> OutputStream os = ftp.storeFileStream(fileName);
>
> byte buf[] = new byte[8192];
> int bytesRead = byteArrayInputStream.read(buf);
> while (bytesRead != -1) {
>        os.write(buf, 0, bytesRead);
>        bytesRead = byteArrayInputStream.read(buf);
> }
> byteArrayInputStream.close();
> os.close();
> ftp.completePendingCommand();
> ftp.logout();
>
> when I debug it...it blocks forever at the call to storeFileStream().
> When it runs while not debugging I get a SocketException (Connection
> time out)...not sure if at same line or another such as os.write()..
>
> I was using version 3.0.1, I just upgraded to 3.1 to see if that would
> help but it has the same problem.  The only difference I can think of
> is that the old server was using Java 6 the new one is Java 7.  One
> other thing that is different is that the EC2 has most ports blocked,
> I've opened port 21 and UDP/DNS.  Is there any other ports that are
> needed for FTP?
>
> What might be causing this?  I'm completely stuck not knowing where to
> look at this point.

Most likely there is a port that is not open.

Try using active FTP mode; that may work better, or may cause issues
if there is a dumb NAT box in the way.

Try adding a protocol command listener:

ftp.addProtocolCommandListener(new PrintCommandListener(new
PrintWriter(System.out), true));

> -Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org