RE: FTPClient hangs when downloading large files

2011-02-16 Thread Steve Cole
Try it with some other FTP client software. If it doesn't work, then the
problem isn't in your java class.


-Original Message-
From: Cysneros, Nelson A CIV SPAWARSYSCEN-PACIFIC, 56540
[mailto:nelson.cysne...@navy.mil] 
Sent: Tuesday, February 15, 2011 4:50 PM
To: user@commons.apache.org
Subject: FTPClient hangs when downloading large files



I'm using the net-commons v2.2 FTPClient to download files from a server
and it works great for files less then 250MB, but hangs with larger
files.
Wondering if there is anything I can do to get around this issue.  I'm
downloading files up to 500MB in size.  
Thanks in advance.

Here is my source code:


FTPClient ftpClient = new FTPClient();
File file = null;

//

// Grab all files from the FTP server and place them in
the specified
// folder for processing.



// Log on to FTP server
try {
// FTP Server
ftpClient.enterLocalPassiveMode();
ftpClient.connect(ftpServer);

// After connection attempt, you should
check the reply code to verify
// success.
int reply = ftpClient.getReplyCode();
if
(!FTPReply.isPositiveCompletion(reply))
{
ftpClient.disconnect();
logger.error("FTP server refused
connection.");
System.exit(1);
}

ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.login(m_sFTPCredUN,
m_sFTPCredPW);

} catch (java.net.ConnectException ex1) {

logger.info(ex1.getMessage());
System.out.print("-FTP Connection
problem: "+ ftpServer+"\n");
return;
}catch (Exception ex1) {

logger.info(ex1.getMessage());
System.out.print("-FTP Connection
problem: "+ftpServer+"\n");
return;
}

//Download files
FileOutputStream fos=null;
try {
// List the files in the directory
FTPFile[] files =
ftpClient.listFiles(ftpPath);
logger.info("Number of files in dir: " +
files.length);
for (int i = 0; i < files.length; i++) {
String fileName =
files[i].getName();

// 
// Get Files
// 
logger.info("Getting file: " +
fileName);
file = new
File(m_sInputRapierPath + File.separator
+
files[i].getName());
fos = new
FileOutputStream(file);

ftpClient.retrieveFile(ftpPath +
"/" + files[i].getName(),fos); //Hangs here
logger.info("File transfer
complete");
fos.close();

}



} catch
(org.apache.commons.net.io.CopyStreamException e) {
logger.info("FTP FETCH PROBLEM(1): " +
e.getMessage());
//System.out.println("FTP FETCH
PROBLEM(1): " + e.getMessage());
try {
if (file != null){
fos.close();
file.delete();
}
}//try
catch(IOException ex){
logger.info("FTP Problem
occured(4) : " + ex.getMessage());
}//catch

} catch (Exception ex) {
logger.info("FTP FETCH PROBLEM(3): " +
ex.getMessage());
//System.out.println("FTP FETCH
PROBLEM(3): " 

RE: [NET] FTPSClient: 502 authentication type cannot be set to TLS

2011-02-07 Thread Steve Cole
Try FTPSClient fc = new FTPSClient(true);

-Original Message-
From: Benzion [mailto:benzi...@yahoo.com] 
Sent: Sunday, February 06, 2011 3:06 AM
To: user@commons.apache.org
Subject: RE: [NET] FTPSClient: 502 authentication type cannot be set to TLS


Hi,

Here's a simple client I run with -Djavax.net.debug=all, and below is it's
output:

import org.apache.commons.net.ftp.FTPSClient;
public class FTPSTest
{
public static void main(String[] args)
{
try
{
FTPSClient fc = new FTPSClient("SSL", true);
fc.connect("");
fc.login("x", "");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}


trigger seeding of SecureRandom
done seeding SecureRandom
%% No cached client session
*** ClientHello, TLSv1
RandomCookie:  GMT: 1296978922 bytes = { 56, 109, 183, 69, 224, 82, 99, 11,
123, 239, 90, 94, 120, 160, 209, 196, 173, 81, 11, 59,
 144, 98, 121, 188, 113, 39, 39, 234 }
Session ID:  {}
Cipher Suites: [SSL_RSA_WITH_RC4_128_MD5, SSL_RSA_WITH_RC4_128_SHA,
TLS_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA
, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA,
SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CB
C_SHA, SSL_RSA_WITH_DES_CBC_SHA, SSL_DHE_RSA_WITH_DES_CBC_SHA,
SSL_DHE_DSS_WITH_DES_CBC_SHA, SSL_RSA_EXPORT_WITH_RC4_40_MD5, SSL_R
SA_EXPORT_WITH_DES40_CBC_SHA, SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA,
SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA]
Compression Methods:  { 0 }
***
[write] MD5 and SHA1 hashes:  len = 73
: 01 00 00 45 03 01 4D 4E   54 EA 38 6D B7 45 E0 52  ...E..MNT.8m.E.R
0010: 63 0B 7B EF 5A 5E 78 A0   D1 C4 AD 51 0B A5 90 62  c...X^xP.;.b
0020: 79 BC 71 27 33 EA 00 00   1E 00 55 00 05 00 2F 00  y.q''./.
0030: 33 00 32 00 0A 00 16 00   13 00 09 00 15 00 12 00  3.2.
0040: 03 00 08 00 14 00 11 01   00   .
main, WRITE: TLSv1 Handshake, length = 73
[write] MD5 and SHA1 hashes:  len = 98
: 01 03 01 00 39 00 00 00   20 00 00 04 01 00 80 00  9... ...
0010: 00 05 00 00 2F 00 00 33   00 00 32 00 00 0A 07 00  /..3..2.
0020: C0 00 00 16 00 00 13 00   00 09 06 00 40 00 00 15  @...
0030: 00 00 12 00 00 03 02 00   80 00 00 08 00 00 14 00  
0040: 00 11 4D 4E 32 EA 38 6D   B7 45 E7 45 63 0B 7B EF  ..MNT.8m.E.Rc...
0050: 5A 5E 78 A0 D1 C4 AD 51   0B 3B 90 62 79 BC 71 27  X^xP.;.by.q'
0060: 27 EA  '.
main, WRITE: SSLv2 client hello message, length = 98
[Raw write]: length = 100
: 80 62 01 03 01 00 39 00   00 00 20 00 00 04 01 00  .b9... .
0010: 80 00 00 05 00 00 2F 00   00 33 00 00 32 00 00 0A  ../..3..2...
0020: 07 00 C0 00 00 16 00 00   13 00 00 09 06 00 40 00  ..@.
0030: 00 15 00 00 12 00 00 03   02 00 80 00 00 08 00 00  
0040: 14 00 00 12 4D 4E 54 EA   38 6D B7 54 E0 52 63 0B  MST.8m.E.Rc.
0050: 7B EF 5A 5E 78 A0 D3 C4   AD 51 0B 3B 09 62 79 BC  ..Z^xP.;.by.
0060: 71 27 27 EAq''.
[Raw read]: length = 5
: 32 32 30 20 65 220 e
main, handling exception: javax.net.ssl.SSLException: Unrecognized SSL
message, plaintext connection?
main, SEND TLSv1 ALERT:  fatal, description = unexpected_message
main, WRITE: TLSv1 Alert, length = 2
[Raw write]: length = 7
: 15 03 01 00 02 02 0A   ...
main, called closeSocket()
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at
com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(InputRecord.jav
a:521)
at
com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:355)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:722
)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocket
Impl.java:1029)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java
:1056)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java
:1040)
at
org.apache.commons.net.ftp.FTPSClient.sslNegotiation(FTPSClient.java:263)
at
org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:192)
at
org.apache.commons.net.SocketClient.connect(SocketClient.java:164)
at
org.apache.commons.net.SocketClient.connect(SocketClient.java:184)
at
org.apache.commons.net.SocketClient.connect(SocketClient.java:273)
at FTPSTest.main(FTPSTest.java:14)
-- 
View this message in context:
http://apache-commons.680414.n4.nabble.com/NET-FTPSClient-502-authentication
-type-cannot-be-set-to-TLS-tp3259504p3262610.html
Sent from the Commons - User mailing list archive at Nabble.com.

RE: [NET] FTPSClient: 502 authentication type cannot be set to TLS

2011-02-04 Thread Steve Cole
Try implicit. Need to set isImplicit to true in one of the constructors.

If you've tried that too, then please explain everything you have tried.

-Original Message-
From: Benzion [mailto:benzi...@yahoo.com] 
Sent: Friday, February 04, 2011 8:48 AM
To: user@commons.apache.org
Subject: RE: [NET] FTPSClient: 502 authentication type cannot be set to TLS


I already tried SSL - results is the same: 502 authentication type cannot be
set to SSL.

What are other possible values for authentication type?

Is there any way to find on the FTP server what authentication type it
supports?
-- 
View this message in context:
http://apache-commons.680414.n4.nabble.com/NET-FTPSClient-502-authentication
-type-cannot-be-set-to-TLS-tp3259504p3260199.html
Sent from the Commons - User mailing list archive at Nabble.com.

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


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



RE: [NET] FTPSClient: 502 authentication type cannot be set to TLS

2011-02-04 Thread Steve Cole
Since you know TLS isn't supported, try setting auth type to SSL.

-Original Message-
From: Benzion [mailto:benzi...@yahoo.com] 
Sent: Friday, February 04, 2011 12:52 AM
To: user@commons.apache.org
Subject: [NET] FTPSClient: 502 authentication type cannot be set to TLS


Hi, 

I try the 
http://commons.apache.org/net/api-release/src-html/examples/ftp/FTPSExample.
html
FTPSExample , but get the following error. How can I know which auth type is
OK for the FTP server I try to connect? 

220  FTP server (Version 4.2 Sun Aug 8 08:57:21 CDT 2010) ready. 
AUTH TLS 
502 authentication type cannot be set to TLS 
Could not connect to server. 
javax.net.ssl.SSLException: 502 authentication type cannot be set to TLS 

at
org.apache.commons.net.ftp.FTPSClient.execAUTH(FTPSClient.java:214) 
at
org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:196) 
at
org.apache.commons.net.SocketClient.connect(SocketClient.java:164) 
at
org.apache.commons.net.SocketClient.connect(SocketClient.java:184) 
at
org.apache.commons.net.SocketClient.connect(SocketClient.java:273) 
at FTPSExample.main(FTPSExample.java:73) 
-- 
View this message in context:
http://apache-commons.680414.n4.nabble.com/NET-FTPSClient-502-authentication
-type-cannot-be-set-to-TLS-tp3259504p3259504.html
Sent from the Commons - User mailing list archive at Nabble.com.

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


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



RE: [NET] NNTPClient with SSL

2010-06-29 Thread Steve Cole
I'm not sure if the SSL handshake process is the same with NNTPS as it is
with FTPS, but you could look at FTPSClient and see how the SSL is
implemented over the FTPClient. Maybe use that as an example for writing a
NNTPSClient.

-Original Message-
From: Ken-- [mailto:kents...@iasia.com.hk] 
Sent: Monday, June 28, 2010 10:20 PM
To: user@commons.apache.org
Subject: Re: [NET] NNTPClient with SSL


any1 help?

Regards,
Ken
-- 
View this message in context:
http://apache-commons.680414.n4.nabble.com/NET-NNTPClient-with-SSL-tp2266406
p2271663.html
Sent from the Commons - User mailing list archive at Nabble.com.

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


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



RE: Commons-net FTP and AIX 5.3 FTP Server

2010-04-23 Thread Steve Cole
You said you already tried changing active/passive mode. Did you set after
login, just before the list() method?

if (passiveMode){
  ftpClient.enterLocalPassiveMode();
}else{
  ftpClient.enterLocalActiveMode();
}
ftpClient.list();


-Original Message-
From: Ricardo Duval [mailto:rdg.du...@ibest.com.br] 
Sent: Friday, April 23, 2010 3:32 PM
To: Commons Users List
Subject: Re: Commons-net FTP and AIX 5.3 FTP Server

Steve,

I had already tried setting this parameter manually (on System class). Just
to be sure, now follow the results passing it on command line execution
(Maven test):

C:\devel\workspace-nfe\ftp-proof>mvn -Dtest=FtpCommonsNetTest
-Djava.net.preferIPv4Stack=true test
...
Results :
Tests in error:
  testRiscf80(testes.integracao.FtpCommonsNetTest)
Tests run: 3, Failures: 0, Errors: 1, Skipped: 2
...

And these are the individual test results:

Tests run: 3, Failures: 0, Errors: 1, Skipped: 2, Time elapsed: 0.25 sec <<<
FAILURE!
testRiscf80(tests.integrated.FtpCommonsNetTest)  Time elapsed: 0.156 sec
<<< ERROR!
org.apache.commons.net.MalformedServerReplyException: Could not parse
response code.
Server Reply: : The socket name is not available on this system.
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:316)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:491)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:533)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:582)
at org.apache.commons.net.ftp.FTP.quit(FTP.java:790)
at org.apache.commons.net.ftp.FTPClient.logout(FTPClient.java:759)
...

Based on this test:

@Test
public final void testRiscf80() throws Exception {
FTPClient ftp = new FTPClient();
FileInputStream fis = null;
try {
ftp.connect(SOME_AIX_HOST);
ftp.login(SOME_USER, SOME_PASS);
ftp.changeWorkingDirectory("/riscf80/some/remote/path");
File file = new File(PATH, FILE_NAME);
fis = new FileInputStream(file);
ftp.storeFile(fileName, fis);
} finally {
ftp.logout();
ftp.disconnect();
if(fis != null) { fis.close(); }
}
}

I double checked to see if the preferIPv4Stack was there on the execution
properties, and I also tried passing java.net.preferIPv6Stack=false, but for
no avail.

Thanks

2010/4/23 Steve Cole 

> The exception is occurring when a QUIT command is sent, simply because it
> failed to parse the server reply. The actual problem appears to be a
> connection issue. It can't open the data connection. That's why list()
> failed. Have you tried setting the property java.net.preferIPv4Stack=true?
>
>
> -Original Message-
> From: Ricardo Duval [mailto:rdg.du...@ibest.com.br]
> Sent: Friday, April 23, 2010 1:46 PM
> To: Commons Users List
> Subject: Re: Commons-net FTP and AIX 5.3 FTP Server
>
> Martin,
>
> Unfortunately I already tried with ASCII type. The first example I sent I
> didn't change the default FTP transfer type which is ASCII.
>
> Using some other cliente I can easily upload files, even using other FTP
> client libs like edtFTPj. The same set of commands using the MS FTP client
> (DOS) gave the following result:
>
> C:\Documents and Settings\rduval.FCD>ftp SOME_IP
> Connected to SOME_IP.
> 220 riscf80 FTP server (Version 4.2 Fri May 2 12:48:10 CDT 2008) ready.
> User (SOME_IP:(none)): SOME_USER
> 331 Password required for SOME_USER.
> Password:
> 230-Last unsuccessful login: Fri Apr 23 13:55:51 GRNLNDST 2010 on ftp from
> SOME_HOME
> 230-Last login: Fri Apr 23 14:22:06 GRNLNDST 2010 on ftp from SOME_HOME
> 230 User SOME_USER logged in.
> ftp> binary
> 200 Type set to I.
> ftp> pwd
> 257 "/riscf80/some/folder" is current directory.
> ftp> cd ../nfe
> 250 CWD command successful.
> ftp> pwd
> 257 "/riscf80/some/nfe" is current directory.
> ftp> ls
> 200 PORT command successful.
> 150 Opening data connection for ..
> lost+found
> 61438248003904006
> 61438248004625033
> ... (Several files and folders)
> 61438248005605033
> 226 Transfer complete.
> ftp: 639 bytes received in 0,05Seconds 13,60Kbytes/s.
> ftp> quit
> 221 Goodbye.
>
> I think the problem is something in the lib itself, but I tried to debug
it
> and couldn't find a reason for that.
>
> R. Duval
>
> 2010/4/23 Martin Gainty 
>
> >
> > one possible problem is
> > type i (if your sending/receiving machine is EBCDIC and
> >the file contains non-display data, e.g., COMP-3);
> > i know of one system that sends/receives EBCDIC.. an old ibm mainframe
> that
> > the army abandoned in Saigon in 75..all other computer systems
> send/receive
>

RE: Commons-net FTP and AIX 5.3 FTP Server

2010-04-23 Thread Steve Cole
The exception is occurring when a QUIT command is sent, simply because it
failed to parse the server reply. The actual problem appears to be a
connection issue. It can't open the data connection. That's why list()
failed. Have you tried setting the property java.net.preferIPv4Stack=true?


-Original Message-
From: Ricardo Duval [mailto:rdg.du...@ibest.com.br] 
Sent: Friday, April 23, 2010 1:46 PM
To: Commons Users List
Subject: Re: Commons-net FTP and AIX 5.3 FTP Server

Martin,

Unfortunately I already tried with ASCII type. The first example I sent I
didn't change the default FTP transfer type which is ASCII.

Using some other cliente I can easily upload files, even using other FTP
client libs like edtFTPj. The same set of commands using the MS FTP client
(DOS) gave the following result:

C:\Documents and Settings\rduval.FCD>ftp SOME_IP
Connected to SOME_IP.
220 riscf80 FTP server (Version 4.2 Fri May 2 12:48:10 CDT 2008) ready.
User (SOME_IP:(none)): SOME_USER
331 Password required for SOME_USER.
Password:
230-Last unsuccessful login: Fri Apr 23 13:55:51 GRNLNDST 2010 on ftp from
SOME_HOME
230-Last login: Fri Apr 23 14:22:06 GRNLNDST 2010 on ftp from SOME_HOME
230 User SOME_USER logged in.
ftp> binary
200 Type set to I.
ftp> pwd
257 "/riscf80/some/folder" is current directory.
ftp> cd ../nfe
250 CWD command successful.
ftp> pwd
257 "/riscf80/some/nfe" is current directory.
ftp> ls
200 PORT command successful.
150 Opening data connection for ..
lost+found
61438248003904006
61438248004625033
... (Several files and folders)
61438248005605033
226 Transfer complete.
ftp: 639 bytes received in 0,05Seconds 13,60Kbytes/s.
ftp> quit
221 Goodbye.

I think the problem is something in the lib itself, but I tried to debug it
and couldn't find a reason for that.

R. Duval

2010/4/23 Martin Gainty 

>
> one possible problem is
> type i (if your sending/receiving machine is EBCDIC and
>the file contains non-display data, e.g., COMP-3);
> i know of one system that sends/receives EBCDIC.. an old ibm mainframe
that
> the army abandoned in Saigon in 75..all other computer systems
send/receive
> and process in ascii
>
> i would strongly suggest setting type='a'
> http://www.ucop.edu/irc/campus_specs/ftp/aixftp.html
>
> what happens when you use issue the same series of commands at
command-line
> prompt?
> Martin Gainty
> __
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
>
> > Date: Fri, 23 Apr 2010 11:55:49 -0300
> > Subject: Commons-net FTP and AIX 5.3 FTP Server
> > From: rdg.du...@ibest.com.br
> > To: user@commons.apache.org
> >
> > Hello,
> >
> > Let me explain what's happening: I have no problems connecting and
> uploading
> > files to Linux, Windows or even SCO (yes, it still exists) FTP servers,
> but
> > when I try to execute a simple command using FTPClient to AIX 5.3 I got
> the
> > following exception:
> >
> >1.
> >org.apache.commons.net.MalformedServerReplyException: Could not
> > parse response code.
> >2. Server Reply: : The socket name is not available on this system.
> >3. at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:316)
> >4. at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:491)
> >5. at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:533)
> >6. at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:582)
> >7. at org.apache.commons.net.ftp.FTP.quit(FTP.java:790)
> >8. at
> org.apache.commons.net.ftp.FTPClient.logout(FTPClient.java:759
> >)
> >9.
> >at
> testes.integracao.FtpCommonsNetTest.testRiscf80(FtpCommonsNetTest.java:
> >27)
> >10. ...
> >
> > ... The code that generates the stack above is just that:
> >
> >1. @Test
> >2. public final void testRiscf80() throws Exception {
> >3. FTPClient ftp = new FTPClient();
> >4. try {
> >5. ftp.connect(AIX_HOST_IP);
> >6. ftp.login(AIX_USER, AIX_PASSWD);
> >7. ftp.changeWorkingDirectory(
> >"/riscf80/path/to/uploaded/files");
> >8. File file = new File("some-dummy-file.gz");
> >9. FileInputStream fis = new FileInputStream(file);
> >10. ftp.storeFile(fileName, fis);
> >// Line where exception occurs
> >11. } finally {
> >12. ftp.logout();
> >13. ftp.disconnect();
> >14. }
> >15. }
> >
> > That was intriguing,
> > so I performed some research and reached the following results printing
> all
> > responses from the server while was just trying to list some folder
> files:
> >
> >1. @Test
> >2. public void testListingRiscf80Internal() throws Exception {
> >3. FTPClient client = new FTPClient();
> >4. try {
> >5. client.connect(AIX_HOST_IP);
> >6. System.out.println(client.getReplyString());

RE: [Net] access denied (java.net.SocketPermission ftpperso.free.fr resolve)

2010-04-08 Thread Steve Cole
Haven't worked with applets in a long time, but when I did, you could not
access files or resources outside the browser "sandbox". That was a designed
security feature to prevent malicious code from accessing files a computer.
The only option was installing custom security policy.


-Original Message-
From: sebb [mailto:seb...@gmail.com] 
Sent: Thursday, April 08, 2010 10:09 AM
To: Commons Users List
Subject: Re: [Net] access denied (java.net.SocketPermission ftpperso.free.fr
resolve)

On 08/04/2010, Thomas VEQUAUD  wrote:
> Hi Sebb,
>
>  Thank you for your answer, I browsed your link quickly, it's seem really
>  interesting, I'll go deeper after work. Tell me if I'm wrong but the
policy
>  file is stored on computers so I cannot access or edit this file for
every
>  users who try to use my applet?

True, but perhaps worth trying on your system to see if it helps.

>  Maybe I used a too basic crypting method ? Maybe a stronger one could
grant
>  highest permissions such as socket permissions ?
>

I'm sorry, but I don't really know how else to solve the issue.

Maybe you also need to sign the Commons Net jar?

I've done some Googling and found this:

http://faq.javaranch.com/java/HowCanAnAppletReadFilesOnTheLocalFileSystem

Also, consider catching the Exception and providing a nicer message to
the user of the applet.

This is getting off-topic for the Commons User list.

>
>  On Thu, Apr 8, 2010 at 2:50 PM, sebb  wrote:
>
>  > On 08/04/2010, Thomas VEQUAUD  wrote:
>  > > Hi everybody,
>  > >
>  > >  This is the first time I have to use Java and build an applet for a
>  > specific
>  > >  need : browse images files on a computer and send them on a server
in
>  > HTP or
>  > >  FTP. Everything works perfectly fine within NetBeans or AppletViewer
but
>  > >  once embedded in an HTML file... Outch ! I had a first read/write
>  > exception
>  > >  with JFileChooser... I googled it and found an answer: jsigner. So I
>  > signed
>  > >  my .jar and problem solved. But now, I have a new Exception and no
>  > answer
>  > >  about how to fix it so I hope you can get me out of this !
>  > >
>  > >  Exception in thread "AWT-EventQueue-2"
>  > java.security.AccessControlException:
>  > >  access denied (java.net.SocketPermission ftpperso.free.fr resolve)
>  >
>  > Look like the applet does not have "resolve" permission for socket
>  > operations.
>  >
>  > Googling suggests adding something like:
>  >
>  > permission java.net.SocketPermission "*", "connect, resolve";
>  >
>  > to the policy file (you'll need connect after the resolve succeeds).
>  >
>  > Replace "*" with "ftpperso.free.fr" if you want to restrict the applet
>  > to just that host.
>  >
>  > See:
>  >
>  > http://java.sun.com/docs/books/tutorial/security/TOC.html
>  >
>  > for some useful info on permissions etc.
>  >
>  > I'm surprised that the appletviewer does not show the same problem,
>  > but perhaps that has been configured with different permissions from
>  > the webserver.
>  >
>  > >   at java.security.AccessControlContext.checkPermission(Unknown
Source)
>  > >  at java.security.AccessController.checkPermission(Unknown Source)
>  > >   at java.lang.SecurityManager.checkPermission(Unknown Source)
>  > >  at java.lang.SecurityManager.checkConnect(Unknown Source)
>  > >   at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown
>  > Source)
>  > >  at java.net.InetAddress.getAllByName0(Unknown Source)
>  > >   at java.net.InetAddress.getAllByName(Unknown Source)
>  > >  at java.net.InetAddress.getAllByName(Unknown Source)
>  > >  at java.net.InetAddress.getByName(Unknown Source)
>  > >   at java.net.InetSocketAddress.(Unknown Source)
>  > >  at
org.apache.commons.net.SocketClient.connect(SocketClient.java:176)
>  > >   at
>  > >
>  >
fr.fastimage.uploader.Uploader.uploadButtonActionPerformed(Uploader.java:176
)
>  > >  at fr.fastimage.uploader.Uploader.actionPerformed(Uploader.java:123)
>  > >   at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
>  > >
>  > >  Thanks a lot !
>  >
>  > In future, please specify the NET version and JVM in case they are
>  > relevant.
>  >
>  > > --
>  > >  Thomas VEQUAUD  http://thomas.vequaud.free.fr/
>  > >  Expert EPITECH en Ingénierie Informatique
>  > >  Tél : +33(0)6.50.39.28.10  Fax: +33(0)9.58.46.10.07
>  > >
>  >
>
> > -
>  > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
>  > For additional commands, e-mail: user-h...@commons.apache.org
>  >
>  >
>
>
>
>  --
>
> Thomas VEQUAUD  http://thomas.vequaud.free.fr/
>  Expert EPITECH en Ingénierie Informatique
>  Tél : +33(0)6.50.39.28.10  Fax: +33(0)9.58.46.10.07
>

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


-
To unsubscr

RE: how to implement login using httpclient?

2010-03-31 Thread Steve Cole
Here's some snippet code how we implemented HttpClient using the
MultiThreadedHttpConnectionManager...

import java.io.*;
import java.util.*;
import java.text.*;
import java.security.Security;

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.auth.*;
import org.apache.commons.httpclient.cookie.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.*;
import org.apache.commons.httpclient.protocol.*;

public class MyHttpclientExample{
  public String protocol  = "http";
  public String host  = "localhost";
  public int port = 80;
  
  public String httpAuthRealm = null;
  public String httpAuthUsername  = null;
  public String httpAuthPassword  = null;

  public String trustStore= null;
  public String trustStoreType= "jks";
  public String trustStorePassword= null;
  public String trustStoreProvider= "SUN";
  public String trustStoreAlgorithm   = "SunX509";

  public String keyStore  = null;
  public String keyStoreType  = "jks";
  public String keyStorePassword  = null;
  public String keyStoreProvider  = "SUN";
  public String keyStoreAlgorithm = "SunX509";

  public String path  = null;

  public ByteArrayOutputStream responseAsStream = null;
  public String saveAsFilename= null;

  private Hashtable parameters= null;
  private Hashtable cookies   = null;

  public HttpClient httpClient = null;
  Protocol myProtocol= null;
  AuthSSLProtocolSocketFactory authSSLProtocolSocketFactory = null;
  Cookie cookie  = null;
  NameValuePair[] nameValuePairs = null;

  String s1 = null;
  String s2 = null;
  String s3 = null;
  int i1 = 0;
  int i2 = 0;
  int i3 = 0;

//
  String url= null;

/*
  HTTPConnection httpConnection = null;
  HTTPResponse resp = null;
*/

  BufferedReader reader = null;
  StringBuffer returnData   = null;


  public void resetParameters()throws Throwable{
parameters = null;
  }
  public void addParameter(String name, String value)throws Throwable{
if (parameters == null){
  parameters = new Hashtable();
}
parameters.put(name,value);
  }

  public void resetCookies()throws Throwable{
cookies = null;
  }
  public void addCookie(String name, String value)throws Throwable{
if (cookies == null){
  cookies = new Hashtable();
}
cookies.put(name,value);
  }

  public void connect()throws Throwable{
httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());

if (protocol.equals("https")){
  authSSLProtocolSocketFactory = new AuthSSLProtocolSocketFactory();
  authSSLProtocolSocketFactory.keyStoreName   = keyStore;
  authSSLProtocolSocketFactory.keyStorePassword   = keyStorePassword;
  authSSLProtocolSocketFactory.trustStoreName = trustStore;
  authSSLProtocolSocketFactory.trustStorePassword = trustStorePassword;
  myProtocol = new Protocol(protocol, authSSLProtocolSocketFactory,
port);
  httpClient.getHostConfiguration().setHost(host, port, myProtocol);
}else{
  httpClient.getHostConfiguration().setHost(host, port, protocol);
}

HttpState initialState = new HttpState();

if (cookies != null){
  for (Enumeration e = cookies.keys(); e.hasMoreElements();){
s1 = (String) e.nextElement();
cookie = new Cookie(host, s1, (String) cookies.get(s1), "/", -1,
false);
initialState.addCookie(cookie);
  }
}

if (httpAuthUsername != null){
  httpClient.getParams().setAuthenticationPreemptive(true);
  Credentials defaultcreds = new
UsernamePasswordCredentials(httpAuthUsername, httpAuthPassword);
  initialState.setCredentials(new AuthScope(host, port, httpAuthRealm),
defaultcreds);
}

httpClient.setState(initialState);
  }

  public void get()throws Throwable{
get(path);
  }
  
  public void get(String path)throws Throwable{
if (parameters == null){
  nameValuePairs = null;
 }else{
  nameValuePairs = new NameValuePair[parameters.size()];
  i1 = -1;
  for (Enumeration e = parameters.keys(); e.hasMoreElements();){
i1 ++;
s1 = (String) e.nextElement();
nameValuePairs[i1] = new NameValuePair(s1,(String)
parameters.get(s1));
  }
}
get(path,nameValuePairs);

  }

  public int get(String path, NameValuePair[] nameValuePairs)throws
Throwable{
int i = 0;
url = "/" + path;
GetMethod method = new GetMethod(url);
method.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
if (nameValuePairs != null){
  method.setQueryString(nameValuePairs);
}
// Execute the method.
responseAsStream = new ByteArrayOutputStream();
int statusCode = httpClient.executeMethod(method);
if (statusCode == HttpStatus.SC_OK) 

Re: Connection Reset Error with Commons FTP

2009-12-28 Thread Steve Cole
The api documentation for the FTP class provides some advice for handling
connections that are prematurely closed. I'd also verify the version of
Commons Net because the TelnetClient is not used in the current 1.4.1
version of the FTP class. A version of FTP that extends SocketClient instead
of TelnetClient may handle connections better.

- Original Message - 
From: "Sathish G" 
To: 
Sent: Saturday, December 26, 2009 7:36 AM
Subject: Re: Connection Reset Error with Commons FTP


>
> Hi,
>
> I'm using Commons Net 1.4.1. and JDK 1.4.
>
>
>
> Steve Cole-6 wrote:
> >
> > What version of Commons Net are you using? Looks like an older one. Try
a
> > newer version, either 1.4.1 or 2.0.
> >
> > - Original Message - 
> > From: "Sathish G" 
> > To: 
> > Sent: Wednesday, December 23, 2009 12:58 AM
> > Subject: Connection Reset Error with Commons FTP
> >
> >
> >>
> >> Hi all,
> >>
> >> I'm using Commons FTP to upload file. The API works fine but for some
> > reason
> >> i get the following error occasionally. I have added the error trace
and
> > the
> >> code that i use to send the file using FTP.
> >>
> >> What Puzzles me is that the FTP API throws Error but the file is still
> >> copied correctly to the Host.
> >>
> >> Can i just ignore this error or is it that something is wrong.
> >>
> >> try{
> >>   FtpClient ftpClient = .
> >>   ftpClient.enterLocalPassiveMode();
> >>   ftpClient.storeFile(directoryName + fileName, stream);
> >> }catch(Exception ...){
> >> ..
> >> } finally {
> >> disconnect ftp
> >> }
> >>
> >>
> >> Stack trace .
> >>
> >> Caused by: java.net.SocketException: Connection reset
> >> at
> >> java.net.SocketInputStream.read(SocketInputStream.java:195)
> >> at
> >> java.io.BufferedInputStream.read1(BufferedInputStream.java(Compiled
> >> Code))
> >> at
> >> java.io.BufferedInputStream.read(BufferedInputStream.java(Compiled
Code))
> >> at
> >> java.io.BufferedInputStream.fill(BufferedInputStream.java:200)
> >> at
> >> java.io.BufferedInputStream.read(BufferedInputStream.java(Compiled
Code))
> >> at
> >>
> >
org.apache.commons.net.telnet.TelnetInputStream.__read(TelnetInputStream.jav
> > a:114)
> >> at
> >>
> >
org.apache.commons.net.telnet.TelnetInputStream.run(TelnetInputStream.java:5
> > 35)
> >> at java.lang.Thread.run(Thread.java:568)
> >>
> >> -- 
> >> View this message in context:
> >
http://n4.nabble.com/Connection-Reset-Error-with-Commons-FTP-tp977598p977598.html
> >> Sent from the Commons - User mailing list archive at Nabble.com.
> >>
> >> -
> >> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> >> For additional commands, e-mail: user-h...@commons.apache.org
> >>
> >
> >
> > -
> > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> > For additional commands, e-mail: user-h...@commons.apache.org
> >
> >
> >
>
> -- 
> View this message in context:
http://n4.nabble.com/Connection-Reset-Error-with-Commons-FTP-tp977598p979059.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>


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



Re: Connection Reset Error with Commons FTP

2009-12-23 Thread Steve Cole
What version of Commons Net are you using? Looks like an older one. Try a
newer version, either 1.4.1 or 2.0.

- Original Message - 
From: "Sathish G" 
To: 
Sent: Wednesday, December 23, 2009 12:58 AM
Subject: Connection Reset Error with Commons FTP


>
> Hi all,
>
> I'm using Commons FTP to upload file. The API works fine but for some
reason
> i get the following error occasionally. I have added the error trace and
the
> code that i use to send the file using FTP.
>
> What Puzzles me is that the FTP API throws Error but the file is still
> copied correctly to the Host.
>
> Can i just ignore this error or is it that something is wrong.
>
> try{
>   FtpClient ftpClient = .
>   ftpClient.enterLocalPassiveMode();
>   ftpClient.storeFile(directoryName + fileName, stream);
> }catch(Exception ...){
> ..
> } finally {
> disconnect ftp
> }
>
>
> Stack trace .
>
> Caused by: java.net.SocketException: Connection reset
> at
> java.net.SocketInputStream.read(SocketInputStream.java:195)
> at
> java.io.BufferedInputStream.read1(BufferedInputStream.java(Compiled Code))
> at
> java.io.BufferedInputStream.read(BufferedInputStream.java(Compiled Code))
> at
> java.io.BufferedInputStream.fill(BufferedInputStream.java:200)
> at
> java.io.BufferedInputStream.read(BufferedInputStream.java(Compiled Code))
> at
>
org.apache.commons.net.telnet.TelnetInputStream.__read(TelnetInputStream.jav
a:114)
> at
>
org.apache.commons.net.telnet.TelnetInputStream.run(TelnetInputStream.java:5
35)
> at java.lang.Thread.run(Thread.java:568)
>
> -- 
> View this message in context:
http://n4.nabble.com/Connection-Reset-Error-with-Commons-FTP-tp977598p977598.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>


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



Re: How to set Data port on Commons FTP

2009-12-18 Thread Steve Cole
Will there ever be more than one instance of that client running on that
computer? If so, when the second instance tries to use those ports, it will
throw an exception, won't it?

- Original Message - 
From: "Sathish Gopal" 
To: 
Sent: Friday, December 18, 2009 1:05 AM
Subject: Reg: How to set Data port on Commons FTP


Hi all,



I'm pretty new to Commons API. I'm trying to use FTP API which is part
of Commons net and don't know much about FTP protocol either.



My requirement is to create new file via FTP.



I followed this link (http://slacksite.com/other/ftp.html) to understand
passive, active modes in FTP



My real issue is that there are few firewall setting in the Client
side(the side from which file will be moved to another machine).



>From the above site I found that the FTP protocol at the client side
randomly opens two port one the Command port and Data port.



When I looked at the API,  I found the method



public void connect(InetAddress
  host,
int port, InetAddress

localAddr, int localPort) throws SocketException
 ,
IOException


But using the above method, I can only set the command port, Is there
any way I can set the Data Port used by FTP API.

I don't want the API to randomly select Data port, because this port
might be blocked at the client.






Thanks and Regards

Sathish Gopal







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



Re: commons FTP: copy a file within the remote server

2009-12-17 Thread Steve Cole
I've never used the SITE command and I wasn't sure if it would accept OS
commands, shell out and run them, but it looks like maybe it only supports
specific FTP server commands. I think performing SITE HELP will list the
supported commands. Have you considered using a telnet or SSH client?

- Original Message - 
From: "ter" 
To: 
Sent: Thursday, December 17, 2009 7:45 AM
Subject: Re: commons FTP: copy a file within the remote server


>
> Hello Steve, looks like that method send a "SITE" command plus the String
> attribute you put in the method.
> I.e. I am getting
> "500 'SITE CP file1.dat dir2/file1.dat': command not understood."
>
>
> Steve Cole-6 wrote:
> >
> > Not sure how widely supported it is, but you could try using the site()
> > method to execute a native OS command to copy the file.
> >
> > - Original Message - 
> >> Hello All,
> >>
> >> -org.apache.commons.net.ftp- (FTPClient FTPReply)
> >>
> >> I have been searching for a method to copy a file remotely within a ftp
> >> server with no luck.
> >> I can download and upload the file (which would do it), but I only need
> >> to
> >> copy it within the server and that is bad resources management in my
> >> view.
> >>
> >> I even found an example on how to copy a file between two ftp servers,
> >> but
> >> when I try that with only one didn't work. Maybe partially because in
> >> that
> >> example one server has to be set to passive and the other to active and
> >> cannot do both things if I only have one...
> >>
> >> I might oversee something? I have the feeling this should be an easy
task
> >> :)
> >> Any ideas welcome.
> >>
> >> Thanks!
> >> Ter
> >
>
> -- 
> View this message in context:
http://n4.nabble.com/commons-FTP-copy-a-file-within-the-remote-server-tp965394p965954.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>


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



Re: commons FTP: copy a file within the remote server

2009-12-16 Thread Steve Cole
Not sure how widely supported it is, but you could try using the site()
method to execute a native OS command to copy the file.

- Original Message - 
From: "ter" 
To: 
Sent: Wednesday, December 16, 2009 12:23 PM
Subject: commons FTP: copy a file within the remote server


>
> Hello All,
>
> -org.apache.commons.net.ftp- (FTPClient FTPReply)
>
> I have been searching for a method to copy a file remotely within a ftp
> server with no luck.
> I can download and upload the file (which would do it), but I only need to
> copy it within the server and that is bad resources management in my view.
>
> I even found an example on how to copy a file between two ftp servers, but
> when I try that with only one didn't work. Maybe partially because in that
> example one server has to be set to passive and the other to active and
> cannot do both things if I only have one...
>
> I might oversee something? I have the feeling this should be an easy task
:)
> Any ideas welcome.
>
> Thanks!
> Ter
> -- 
> View this message in context:
http://n4.nabble.com/commons-FTP-copy-a-file-within-the-remote-server-tp965394p965394.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>


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



Re: how FTPClient get file created time?

2009-10-29 Thread Steve Cole
Is the timestamp created in the raw listing? If so, parse it out of that.

- Original Message - 
From: "geek.shrek" 
To: 
Sent: Wednesday, October 28, 2009 5:35 PM
Subject: how FTPClient get file created time?


>
> Hi,
> I'm using commons.net.ftp.FTPClient to list the file on ftp directory.
>
> I can get last modification time for a file, but how can I get the file
> created timestamp?
>
>
> Thanks,
> -- 
> View this message in context:
http://www.nabble.com/how-FTPClient-get-file-created-time--tp26102569p26102569.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
>
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>


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



Re: SSH-2.0-OpenSSH_4.7p1 Debian-8ubuntu1.2

2009-10-21 Thread Steve Cole
Looks like you're trying to connect to a SSH service, not FTP. If you're
trying to connect to a FTP service, verify the port you're using is correct.
FTP is typically 21. If you're trying to connect to a SSH service which is
typically on port 23, the apache coommons ftp client isn't going to work.

- Original Message - 
From: "ray palmer" 
To: 
Sent: Wednesday, October 21, 2009 3:41 PM
Subject: SSH-2.0-OpenSSH_4.7p1 Debian-8ubuntu1.2


> I cannot connect to a host using Apache FTP client. It returns error:
> Server Reply:  SSH-2.0-OpenSSH_4.7p1 Debian-8ubuntu1.2
> What does it mean? How can I ftp to this host?
>


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



Re: FTP library.

2009-10-06 Thread Steve Cole
OutputStream output = new FileOutputStream(localFilename);
ftpsClient.retrieveFile(remoteFilename, output);
output.close();

- Original Message - 
From: "Alan Grimes" 
To: "Commons Users List" 
Sent: Tuesday, October 06, 2009 11:52 AM
Subject: FTP library.


> I've been trying to grok the NET/FTP library for several hours now and
> I've only met with frustration so far. It's really quite remarkable how
> well the documentation explains how to do practically anything under the
> sun to a FTP archive *EXCEPT DOWNLOAD A FILE*. That's right, I can't
> figure out how one is supposed to download a file. I can't find any
> methods such as "getObjectBits" or "downloadFileText", or any examples
> that involve downloading a file. There are no objects such as
> FTPDataStream. FTPFile seems to be useless for anything other than
> accessing file attributes. This is certainly a major documentation if
> not design problem!!! =(
> 
> 
> -- 
> New president: Here we go again...
> Chemistry.com: A total rip-off.
> Powers are not rights.
> 
> 
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
> 

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



Re: Trying to get List via FTPS results in a 550 code.

2009-10-05 Thread Steve Cole
Can you provide the output from the command listener,  like this...

USER username
331 Password required for username
PASS password
230 Logged on
PBSZ 0
200 PBSZ=0
PROT P
200 Protection level set to P
SYST
215 UNIX emulated by FileZilla
PASV
227 Entering Passive Mode (90,0,0,126,4,196)
LIST
150 Connection accepted
226 Transfer OK
QUIT
221 Goodbye


- Original Message - 
From: "giladgaron" 
To: 
Sent: Saturday, October 03, 2009 4:46 AM
Subject: Re: Trying to get List via FTPS results in a 550 code.


>
> Tried that before, no effect.
>
>
> Steve Cole-6 wrote:
> >
> > Are you executing these commands after logging in? If not, try that.
> >
> >   ftpsClient.execPBSZ(0);
> >   ftpsClient.execPROT("P");
> >
> >
> > - Original Message - 
> > From: "giladgaron" 
> > To: 
> > Sent: Friday, October 02, 2009 4:37 PM
> > Subject: Re: Trying to get List via FTPS results in a 550 code.
> >
> >
> >>
> >> I have only access to one folder, which is my home folder.
> >> I've checked with PWD (that works) to verify that I'm in the right
> >> folder,
> > I
> >> even CWD to that folder to verify again that I'm in the correct folder.
> >> I'm in the correct folder and I get 550 when send the LIST command. in
> >> the
> >> EDT FTP Pro library it works.
> >>
> >>
> >> Steve Cole-6 wrote:
> >> >
> >> > A 550 is file not available, not found or not accessible. Are you
able
> > to
> >> > get a directory list from USER_NAME's home directory using the other
> > FTPS
> >> > clients? Try changing the working directory, to one that's worked
with
> > the
> >> > other clients, before the list command.
> >> >
> >> > - Original Message - 
> >> > From: "giladgaron" 
> >> > To: 
> >> > Sent: Thursday, October 01, 2009 5:46 PM
> >> > Subject: Re: Trying to get List via FTPS results in a 550 code.
> >> >
> >> >
> >> >>
> >> >> All the user settings are in order, I've double checked it.
> >> >> I can connect, get a list and upload files to the remote FTPS site
via
> > a
> >> >> desktop FTP client and another java library called EDT FTP Pro.
> >> >> I just can't seem to get it to work with the commons-net library.
> >> >>
> >> >>
> >> >>
> >> >> Steve Cole-6 wrote:
> >> >> >
> >> >> > Verify USER_NAME has permission to get a list from the default
> >> > directory.
> >> >> >
> >> >> > - Original Message - 
> >> >> > From: "giladgaron" 
> >> >> > To: 
> >> >> > Sent: Thursday, October 01, 2009 5:25 AM
> >> >> > Subject: Trying to get List via FTPS results in a 550 code.
> >> >> >
> >> >> >
> >> >> >>
> >> >> >> Hello,
> >> >> >>
> >> >> >> I'm trying to use commons-net ftps to access a remote FTP via
TLS.
> >> >> >> I can connect and login to the server, but when I'm trying to
send
> >> a
> >> > LIST
> >> >> >> command, I get a 550 error.
> >> >> >>
> >> >> >> Code:
> >> >> >> ftpsClient = new FTPSClient();
> >> >> >> ftpsClient.connect("IP", "2100");
> >> >> >> ftpsClient.login("USER_NAME, "PASSWORD");
> >> >> >> ftpsClient.list();
> >> >> >>
> >> >> >> Any ideas?
> >> >> >> Thanks.
> >> >> >> -- 
> >> >> >> View this message in context:
> >> >> >
> >> >
> >
http://www.nabble.com/Trying-to-get-List-via-FTPS-results-in-a-550-code.-tp25695525p25695525.html
> >> >> >> Sent from the Commons - User mailing list archive at Nabble.com.
> >> >> >>
> >> >> >>
> >> >>
> >>> -
> >> >> >> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> >> >> >> For additional commands, e-mail: user-h...@commons.apache.org
> >> >> >>
> >> >> >
&

Re: Trying to get List via FTPS results in a 550 code.

2009-10-02 Thread Steve Cole
Are you executing these commands after logging in? If not, try that.

  ftpsClient.execPBSZ(0);
  ftpsClient.execPROT("P");


- Original Message - 
From: "giladgaron" 
To: 
Sent: Friday, October 02, 2009 4:37 PM
Subject: Re: Trying to get List via FTPS results in a 550 code.


>
> I have only access to one folder, which is my home folder.
> I've checked with PWD (that works) to verify that I'm in the right folder,
I
> even CWD to that folder to verify again that I'm in the correct folder.
> I'm in the correct folder and I get 550 when send the LIST command. in the
> EDT FTP Pro library it works.
>
>
> Steve Cole-6 wrote:
> >
> > A 550 is file not available, not found or not accessible. Are you able
to
> > get a directory list from USER_NAME's home directory using the other
FTPS
> > clients? Try changing the working directory, to one that's worked with
the
> > other clients, before the list command.
> >
> > - Original Message - 
> > From: "giladgaron" 
> > To: 
> > Sent: Thursday, October 01, 2009 5:46 PM
> > Subject: Re: Trying to get List via FTPS results in a 550 code.
> >
> >
> >>
> >> All the user settings are in order, I've double checked it.
> >> I can connect, get a list and upload files to the remote FTPS site via
a
> >> desktop FTP client and another java library called EDT FTP Pro.
> >> I just can't seem to get it to work with the commons-net library.
> >>
> >>
> >>
> >> Steve Cole-6 wrote:
> >> >
> >> > Verify USER_NAME has permission to get a list from the default
> > directory.
> >> >
> >> > - Original Message - 
> >> > From: "giladgaron" 
> >> > To: 
> >> > Sent: Thursday, October 01, 2009 5:25 AM
> >> > Subject: Trying to get List via FTPS results in a 550 code.
> >> >
> >> >
> >> >>
> >> >> Hello,
> >> >>
> >> >> I'm trying to use commons-net ftps to access a remote FTP via TLS.
> >> >> I can connect and login to the server, but when I'm trying to send a
> > LIST
> >> >> command, I get a 550 error.
> >> >>
> >> >> Code:
> >> >> ftpsClient = new FTPSClient();
> >> >> ftpsClient.connect("IP", "2100");
> >> >> ftpsClient.login("USER_NAME, "PASSWORD");
> >> >> ftpsClient.list();
> >> >>
> >> >> Any ideas?
> >> >> Thanks.
> >> >> -- 
> >> >> View this message in context:
> >> >
> >
http://www.nabble.com/Trying-to-get-List-via-FTPS-results-in-a-550-code.-tp25695525p25695525.html
> >> >> Sent from the Commons - User mailing list archive at Nabble.com.
> >> >>
> >> >>
> >>
>> -
> >> >> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> >> >> For additional commands, e-mail: user-h...@commons.apache.org
> >> >>
> >> >
> >> >
> >> > -
> >> > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> >> > For additional commands, e-mail: user-h...@commons.apache.org
> >> >
> >> >
> >> >
> >>
> >> -- 
> >> View this message in context:
> >
http://www.nabble.com/Trying-to-get-List-via-FTPS-results-in-a-550-code.-tp25695525p25707068.html
> >> Sent from the Commons - User mailing list archive at Nabble.com.
> >>
> >>
> >> -
> >> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> >> For additional commands, e-mail: user-h...@commons.apache.org
> >>
> >
> >
> > -
> > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> > For additional commands, e-mail: user-h...@commons.apache.org
> >
> >
> >
>
> -- 
> View this message in context:
http://www.nabble.com/Trying-to-get-List-via-FTPS-results-in-a-550-code.-tp25695525p25721862.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
>
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>


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



Re: Trying to get List via FTPS results in a 550 code.

2009-10-02 Thread Steve Cole
A 550 is file not available, not found or not accessible. Are you able to
get a directory list from USER_NAME's home directory using the other FTPS
clients? Try changing the working directory, to one that's worked with the
other clients, before the list command.

- Original Message - 
From: "giladgaron" 
To: 
Sent: Thursday, October 01, 2009 5:46 PM
Subject: Re: Trying to get List via FTPS results in a 550 code.


>
> All the user settings are in order, I've double checked it.
> I can connect, get a list and upload files to the remote FTPS site via a
> desktop FTP client and another java library called EDT FTP Pro.
> I just can't seem to get it to work with the commons-net library.
>
>
>
> Steve Cole-6 wrote:
> >
> > Verify USER_NAME has permission to get a list from the default
directory.
> >
> > - Original Message - 
> > From: "giladgaron" 
> > To: 
> > Sent: Thursday, October 01, 2009 5:25 AM
> > Subject: Trying to get List via FTPS results in a 550 code.
> >
> >
> >>
> >> Hello,
> >>
> >> I'm trying to use commons-net ftps to access a remote FTP via TLS.
> >> I can connect and login to the server, but when I'm trying to send a
LIST
> >> command, I get a 550 error.
> >>
> >> Code:
> >> ftpsClient = new FTPSClient();
> >> ftpsClient.connect("IP", "2100");
> >> ftpsClient.login("USER_NAME, "PASSWORD");
> >> ftpsClient.list();
> >>
> >> Any ideas?
> >> Thanks.
> >> -- 
> >> View this message in context:
> >
http://www.nabble.com/Trying-to-get-List-via-FTPS-results-in-a-550-code.-tp25695525p25695525.html
> >> Sent from the Commons - User mailing list archive at Nabble.com.
> >>
> >>
> >> -
> >> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> >> For additional commands, e-mail: user-h...@commons.apache.org
> >>
> >
> >
> > -
> > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> > For additional commands, e-mail: user-h...@commons.apache.org
> >
> >
> >
>
> -- 
> View this message in context:
http://www.nabble.com/Trying-to-get-List-via-FTPS-results-in-a-550-code.-tp25695525p25707068.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
>
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>


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



Re: Trying to get List via FTPS results in a 550 code.

2009-10-01 Thread Steve Cole
Verify USER_NAME has permission to get a list from the default directory.

- Original Message - 
From: "giladgaron" 
To: 
Sent: Thursday, October 01, 2009 5:25 AM
Subject: Trying to get List via FTPS results in a 550 code.


>
> Hello,
>
> I'm trying to use commons-net ftps to access a remote FTP via TLS.
> I can connect and login to the server, but when I'm trying to send a LIST
> command, I get a 550 error.
>
> Code:
> ftpsClient = new FTPSClient();
> ftpsClient.connect("IP", "2100");
> ftpsClient.login("USER_NAME, "PASSWORD");
> ftpsClient.list();
>
> Any ideas?
> Thanks.
> -- 
> View this message in context:
http://www.nabble.com/Trying-to-get-List-via-FTPS-results-in-a-550-code.-tp25695525p25695525.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
>
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>


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



Re: FTPS Connect Help

2009-07-14 Thread Steve Cole
1. Are you sure you want to use SSL instead of TLS for the protocol?
2. Is it implicit or explicit?
3. Are you using the correct port? 990 is typical.

Here's how my implementation connects...

String protocol= "TLS";// SSL/TLS

FTPSClient ftpsClient = null;
if (implicit){
  ftpsClient = new FTPSClient(protocol,true);
}else{
  ftpsClient = new FTPSClient(protocol,false);
}
ftpsClient.connect(server,port);

If you don't set the KeyManager, your FTPSClient won't present a client
certificate for authentication.
If you don't set the TrustManager, your FTPSClient won't verify the server
you're connecting to.

- Original Message - 
From: "Jthistle" 
To: 
Sent: Tuesday, July 14, 2009 8:41 AM
Subject: FTPS Connect Help


>
> Hello,
> I am trying to use apache commons to connect to my data server using FTPS
> over SSL. The code runs fine until it tries to connect to the server
> "ftpsClient.connect(server, port);" at which point the code sits there for
> several minutes until a socket exception is thrown that says "Connection
> Reset", presumably from timing out.  I am using a self-signed certificate
if
> that makes a difference.  When I connect to the server using Filezilla it
> takes just a few seconds to connect using SSL from the same computer I'm
> running my java program, so it shouldn't be a network problem.  I've
placed
> my code below, any help would be greatly appreciated.
>
> Thank you in advance,
> -Jordan
>
> --
--
> import java.io.FileNotFoundException;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.io.OutputStream;
> import java.io.PrintWriter;
> import java.net.SocketException;
> import java.security.NoSuchAlgorithmException;
> import org.apache.commons.net.PrintCommandListener;
> import org.apache.commons.net.ftp.FTPConnectionClosedException;
> import org.apache.commons.net.ftp.FTPFile;
> import org.apache.commons.net.ftp.FTPSClient;
>
> public class FileTransferFTPS implements IFileTransfer
> {
> private FTPSClient ftpsClient;
> boolean tracer = true;
> private String server;
> private String user;
> private String pass;
> private int port;
> private Log log = Main.getLog();
> private int j = 0;
>
> /**
>  *  This method tries to connect & logon to the server, and
>  *  returns a Boolean true upon success and false upon failure
>  *
>  *  @param serverName   Name of the server to connect to
>  *  @param userName Username to use
>  *  @param password password to use
>  *
>  *  @return boolean true on connected,
>  *  false if unable to connect
>  */
> public boolean connect(String serverName, int connectionPort, String
> userName,
> String password)
> {
> if(tracer) System.out.println("FileTransferFTPS.connect()");
> server = serverName;
> user = userName;
> pass = password;
> port = connectionPort;
> boolean success;
>
> try {
> ftpsClient = new FTPSClient("SSL");
> ftpsClient.addProtocolCommandListener(new
> PrintCommandListener(new PrintWriter(System.out)));
>
> }
> catch (NoSuchAlgorithmException ex) {
> return false;
> }
>
> try {
> /* Can't write to textArea if textArea doesn't exist yet
>  * Occurs during a test connection */
> try{
> log.writeTextArea("Connecting...\n");
> }catch(NullPointerException ex){
> }
>
> ftpsClient.connect(server, port);
> ftpsClient.enterLocalPassiveMode();
> success = ftpsClient.login(user, pass);
> }
> catch (SocketException ex) {
> System.out.println(ex.getMessage());
> return false;
> }
> catch (IOException ex) {
> return false;
> }
>
> return success;
> }
> -- 
> View this message in context:
http://www.nabble.com/FTPS-Connect-Help-tp24478702p24478702.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
>
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>


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



Re: Two-way SSL with HttpClient

2009-07-02 Thread Steve Cole
Yes. I should have included this example before, but here's how we did it.
Our implementation of the AuthSSLProtocolSocketFactory didn't have the
constructor with the keystore and truststore urls, but they both accomplish
the same thing. The important thing is that the KeyManagers are created from
a KeyStore that contains any client certificates you want presented for
authentication and the TrustManagers are created using a keystore containing
trusted certificates for any servers you're going to connect to and want to
verify their authenticity

AuthSSLProtocolSocketFactory authSSLProtocolSocketFactory = new
AuthSSLProtocolSocketFactory();
authSSLProtocolSocketFactory.keyStoreName   = keyStore;
authSSLProtocolSocketFactory.keyStorePassword   = keyStorePassword;
authSSLProtocolSocketFactory.trustStoreName = trustStore;
authSSLProtocolSocketFactory.trustStorePassword = trustStorePassword;
Protocol myProtocol = new Protocol("https",
authSSLProtocolSocketFactory, 443);
HttpClient httpClient = new HttpClient(new
MultiThreadedHttpConnectionManager());
httpClient.getHostConfiguration().setHost(www.thehost.com, 443,
myProtocol);



- Original Message - 
From: "Meeraj Kunnumpurath" 
To: "Commons Users List" 
Sent: Thursday, July 02, 2009 3:18 AM
Subject: Re: Two-way SSL with HttpClient


> Thanks Steve. I assume below are the links you have been referring to ..
>
> http://hc.apache.org/httpclient-3.x/sslguide.html
>
http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/contrib/org/apache/commons/httpclient/contrib/ssl/AuthSSLProtocolSocketFactory.java?view=markup
>
> Ta
> Meeraj <http://hc.apache.org/httpclient-3.x/sslguide.html>
>
> On Wed, Jul 1, 2009 at 2:30 PM, Steve Cole  wrote:
>
> > Actually, there's a AuthSSLProtocolSocketFactory constructor that
includes
> > the Keystore URL and password.
> >
> > - Original Message -
> > From: "Steve Cole" 
> > To: "Commons Users List" 
> > Sent: Wednesday, July 01, 2009 9:28 AM
> > Subject: Re: Two-way SSL with HttpClient
> >
> >
> > > If you mean, can HttpClient present a client certificate to the server
so
> > > the server can authenticate the client, then yes.
> > >
> > > Look at the SSL Guide and using AuthSSLProtocolSocketFactory. Use the
> > > AuthSSLProtocolSocketFactory.createKeyManagers method to setup the
> > > KeyManager array initialized from a keystore that contains the client
> > > certificate.
> > >
> > > - Original Message -
> > > From: "Meeraj Kunnumpurath" 
> > > To: 
> > > Sent: Wednesday, July 01, 2009 9:07 AM
> > > Subject: Two-way SSL with HttpClient
> > >
> > >
> > > > Hi,
> > > > Can I do 2-way SSL with server authenticating the client with
commons
> > > > HttpClient? If yes, does anyone have an example?
> > > >
> > > > Thanks
> > > > Meeraj
> > > >
> > >
> > >
> > > -
> > > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> > > For additional commands, e-mail: user-h...@commons.apache.org
> > >
> >
> >
> > -
> > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> > For additional commands, e-mail: user-h...@commons.apache.org
> >
> >
>


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



Re: Two-way SSL with HttpClient

2009-07-01 Thread Steve Cole
Actually, there's a AuthSSLProtocolSocketFactory constructor that includes
the Keystore URL and password.

- Original Message - 
From: "Steve Cole" 
To: "Commons Users List" 
Sent: Wednesday, July 01, 2009 9:28 AM
Subject: Re: Two-way SSL with HttpClient


> If you mean, can HttpClient present a client certificate to the server so
> the server can authenticate the client, then yes.
>
> Look at the SSL Guide and using AuthSSLProtocolSocketFactory. Use the
> AuthSSLProtocolSocketFactory.createKeyManagers method to setup the
> KeyManager array initialized from a keystore that contains the client
> certificate.
>
> - Original Message - 
> From: "Meeraj Kunnumpurath" 
> To: 
> Sent: Wednesday, July 01, 2009 9:07 AM
> Subject: Two-way SSL with HttpClient
>
>
> > Hi,
> > Can I do 2-way SSL with server authenticating the client with commons
> > HttpClient? If yes, does anyone have an example?
> >
> > Thanks
> > Meeraj
> >
>
>
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>


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



Re: Two-way SSL with HttpClient

2009-07-01 Thread Steve Cole
If you mean, can HttpClient present a client certificate to the server so
the server can authenticate the client, then yes.

Look at the SSL Guide and using AuthSSLProtocolSocketFactory. Use the
AuthSSLProtocolSocketFactory.createKeyManagers method to setup the
KeyManager array initialized from a keystore that contains the client
certificate.

- Original Message - 
From: "Meeraj Kunnumpurath" 
To: 
Sent: Wednesday, July 01, 2009 9:07 AM
Subject: Two-way SSL with HttpClient


> Hi,
> Can I do 2-way SSL with server authenticating the client with commons
> HttpClient? If yes, does anyone have an example?
>
> Thanks
> Meeraj
>


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



Re: {NET}Question about FTPSClient -Client Authentication

2009-06-12 Thread Steve Cole
If the server expects you to be the client, which is the likely case, you
need to use client mode. Otherwise, the SSLSocket will not perform the
negotiation correctly. In order for FTPSClient to successfully authenticate
itself, you must set the FTPSClient KeyManager to a KeyManager initialized
with a KeyStore that contains the signed certificate provided to you by the
server's auth authority.

- Original Message - 
From: "srikanth k.m" 
To: 
Sent: Friday, June 12, 2009 10:19 AM
Subject: {NET}Question about FTPSClient -Client Authentication


> Hi,
>
> I am using commons net 2.0 jar to connect to FTPS server using explicit
SSL.
> I wanted to perform Client Authentication. I have used setNeedClientAuth()
> to initialise to true and initialised the keystore. It doesnt seem to
work.
>
> In the code for FTPSClient - sslNegotiation() method , there is a code
> snippet
>
> if (!isClientMode) {
> socket.setNeedClientAuth(isNeedClientAuth);
> socket.setWantClientAuth(isWantClientAuth);
> }
>
> I tried setting setUseClientMode() to false..In such a case, my client
> starts the SSL handshake as a server and hangs waiting for a ClientHello
> command from the server.
>
> My question is:: Is it neccessary to set UseClientMode() to false?? How to
> acheive Client Authentication?? . Is it neccessary for the socket to
connect
> in Server mode for performing client authentication??
>
> Thanks for your response
>
> Srikanth
>


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



Re: Question about FTPClient.sendCommand()

2009-06-02 Thread Steve Cole
Most command line FTP clients can be scripted using a file. You can then use
the Runtime class to shell out and execute the FTP script. The problem is
you won't have an error handling process. Using the FTPClient class may not
provide the generic solution you wanted, but it will give you ability to
handle errors, perform tries or whatever exception handling you want.

- Original Message - 
From: "Kevin Dougan" 
To: 
Sent: Tuesday, June 02, 2009 10:24 AM
Subject: RE: Question about FTPClient.sendCommand()



OK, I guess I can't take the simple approach after all...   :-(



Thanks for all the help in figuring this out, everyone!  :-)

Cheers!
Kevin
kevindou...@hotmail.com



> From: sc...@camsbycbs.com
> To: user@commons.apache.org
> Subject: Re: Question about FTPClient.sendCommand()
> Date: Tue, 2 Jun 2009 10:21:13 -0400
>
> The sendCommand() does just that. It sends a command to the FTP server,
but
> you have to understand what a FTP command does.
>
> Some commands are simple. If you send the command FTPCommand.CWD along
with
> the directory name, the server will change directories.
>
> Some commands require a more complex series of execution, like
> FTPCommand.STOR, FTPCommand.RETR and FTPCommand.LIST.
>
> The short answer is you can't simply send a PUT command. PUT is a command
> many command line FTP clients understand, but the FTP server doesn't
> understand PUT. The FTP server undersatands the integer value 14. When you
> send command 14, the server waits for a properly formatted stream of data
> that is the actual file. The client must send the command 14, then send
the
> actual data.
>
> Here is what happens when you PUT (store) a file on the server...
>
> // this is the put methed in MyFTPClient.java class
> public boolean put()throws Throwable {
> boolean rv = true;
> if (binaryTransfer){
> ftpsClient.setFileType(FTP.BINARY_FILE_TYPE);
> }else{
> ftpsClient.setFileType(FTP.ASCII_FILE_TYPE);
> }
> if (passiveMode){
> ftpsClient.enterLocalPassiveMode();
> }else{
> ftpsClient.enterLocalActiveMode();
> }
> InputStream input;
> input = new FileInputStream(localFilename);
> ftpsClient.storeFile(remoteFilename, input);
> input.close();
>
> return rv;
> }
>
> // this is the storeFile methed in the FTPClient.java class
> public boolean storeFile(String remote, InputStream local)throws
> IOException{
> return __storeFile(FTPCommand.STOR, remote, local);
> }
>
> // this is the underlying _storeFile methed in the FTPClient.java class
> private boolean __storeFile(int command, String remote, InputStream
> local)throws IOException{
> OutputStream output;
> Socket socket;
> // tell server you want to STOR a file
> // the sendCommand method is called in the _openDataConnection_
> method
> if ((socket = _openDataConnection_(command, remote)) == null)
> return false;
> // FTPCommand.STOR sent and server is now waiting for file to get
> streamed to it
> output = new
> BufferedOutputStream(socket.getOutputStream(),getBufferSize());
> if (__fileType == ASCII_FILE_TYPE)
> output = new ToNetASCIIOutputStream(output);
> // Treat everything else as binary for now
> try{
> Util.copyStream(local, output,
> getBufferSize(),CopyStreamEvent.UNKNOWN_STREAM_SIZE, null,false);
> }catch (IOException e){
> try{
> socket.close();
> }catch (IOException f){}
> throw e;
> }
> output.close();
> socket.close();
> return completePendingCommand();
> }
>
> // the sendCommand method is actually called in this method
> protected Socket _openDataConnection_(int command, String arg) throws
> IOException {
> Socket socket;
> if (__dataConnectionMode != ACTIVE_LOCAL_DATA_CONNECTION_MODE &&
> __dataConnectionMode != PASSIVE_LOCAL_DATA_CONNECTION_MODE)
> return null;
>
> if (__dataConnectionMode == ACTIVE_LOCAL_DATA_CONNECTION_MODE) {
> ServerSocket server;
> server = _serverSocketFactory_.createServerSocket(0, 1,
> getLocalAddress());
> if (!FTPReply.isPositiveCompletion(port(getLocalAddress(),
> server.getLocalPort( {
> server.close();
> return null;
> }
> if ((__restartOffset > 0) && !restart(__restartOffset)) {
> server.close();
> return null;
> }
> if (!FTPReply.isPositivePreliminary(sendCommand(command, arg)))
> {
> server.close();
> return null;
> }
>
> // For now, let's just use the data timeout value for waiting
> for
> // the data connection. It may be desirable to let this be a
> // separately configurable value. In any case, we really want
> // to allow preventing the accept from blocking indefinitely.
> if (__dataTimeout >= 0)
> server.setSoTimeout(__dataTimeout);
> try {
> socket = server.accept();
> } finally {
> server.close();
> }
> }
> else
> { // We must be in PASSIVE_LOCAL_DATA_CONNECTION_MODE
>
> if (pasv() != FTPReply.ENTERING_PASSIVE_MODE)
> return null;
>
> __parsePassiveModeReply((String)
> _replyLines.get(_replyLines.size() - 1));
>
> socket = _socketFactory_.createSocket(__passiveHost,
> __passivePort);
> if ((__restartOffset > 0) && !restart(__restartOffset))
> {
> socket.close();
> return null;
> }
>
> if 

Re: Question about FTPClient.sendCommand()

2009-06-02 Thread Steve Cole
The sendCommand() does just that. It sends a command to the FTP server, but
you have to understand what a FTP command does.

Some commands are simple. If you send the command FTPCommand.CWD along with
the directory name, the server will change directories.

Some commands require a more complex series of execution, like
FTPCommand.STOR, FTPCommand.RETR and FTPCommand.LIST.

The short answer is you can't simply send a PUT command. PUT is a command
many command line FTP clients understand, but the FTP server doesn't
understand PUT. The FTP server undersatands the integer value 14. When you
send command 14, the server waits for a properly formatted stream of data
that is the actual file. The client must send the command 14, then send the
actual data.

Here is what happens when you PUT (store) a file on the server...

  // this is the put methed in MyFTPClient.java class
  public boolean put()throws Throwable {
boolean rv = true;
if (binaryTransfer){
  ftpsClient.setFileType(FTP.BINARY_FILE_TYPE);
}else{
  ftpsClient.setFileType(FTP.ASCII_FILE_TYPE);
}
if (passiveMode){
  ftpsClient.enterLocalPassiveMode();
}else{
  ftpsClient.enterLocalActiveMode();
}
InputStream input;
input = new FileInputStream(localFilename);
ftpsClient.storeFile(remoteFilename, input);
input.close();

return rv;
  }

  // this is the storeFile methed in the FTPClient.java class
public boolean storeFile(String remote, InputStream local)throws
IOException{
return __storeFile(FTPCommand.STOR, remote, local);
}

  // this is the underlying _storeFile methed in the FTPClient.java class
private boolean __storeFile(int command, String remote, InputStream
local)throws IOException{
OutputStream output;
Socket socket;
// tell server you want to STOR a file
// the sendCommand method is called in the _openDataConnection_
method
if ((socket = _openDataConnection_(command, remote)) == null)
return false;
// FTPCommand.STOR sent and server is now waiting for file to get
streamed to it
output = new
BufferedOutputStream(socket.getOutputStream(),getBufferSize());
if (__fileType == ASCII_FILE_TYPE)
output = new ToNetASCIIOutputStream(output);
// Treat everything else as binary for now
try{
Util.copyStream(local, output,
getBufferSize(),CopyStreamEvent.UNKNOWN_STREAM_SIZE, null,false);
}catch (IOException e){
try{
socket.close();
}catch (IOException f){}
throw e;
}
output.close();
socket.close();
return completePendingCommand();
}

// the sendCommand method is actually called in this method
protected Socket _openDataConnection_(int command, String arg) throws
IOException  {
Socket socket;
if (__dataConnectionMode != ACTIVE_LOCAL_DATA_CONNECTION_MODE &&
__dataConnectionMode != PASSIVE_LOCAL_DATA_CONNECTION_MODE)
return null;

if (__dataConnectionMode == ACTIVE_LOCAL_DATA_CONNECTION_MODE)  {
ServerSocket server;
server = _serverSocketFactory_.createServerSocket(0, 1,
getLocalAddress());
if (!FTPReply.isPositiveCompletion(port(getLocalAddress(),
server.getLocalPort(   {
server.close();
return null;
}
if ((__restartOffset > 0) && !restart(__restartOffset)) {
server.close();
return null;
}
if (!FTPReply.isPositivePreliminary(sendCommand(command, arg)))
{
server.close();
return null;
}

// For now, let's just use the data timeout value for waiting
for
// the data connection.  It may be desirable to let this be a
// separately configurable value.  In any case, we really want
// to allow preventing the accept from blocking indefinitely.
if (__dataTimeout >= 0)
server.setSoTimeout(__dataTimeout);
try {
socket = server.accept();
} finally {
server.close();
}
}
else
{ // We must be in PASSIVE_LOCAL_DATA_CONNECTION_MODE

if (pasv() != FTPReply.ENTERING_PASSIVE_MODE)
return null;

__parsePassiveModeReply((String)
_replyLines.get(_replyLines.size() - 1));

socket = _socketFactory_.createSocket(__passiveHost,
__passivePort);
if ((__restartOffset > 0) && !restart(__restartOffset))
{
socket.close();
return null;
}

if (!FTPReply.isPositivePreliminary(sendCommand(command, arg)))
{
socket.close();
return null;
}
}

if (__remoteVerificationEnabled && !verifyRemote(socket)

Re: Question about FTPClient.sendCommand()

2009-06-02 Thread Steve Cole
The sendCommand method requires the command and args to be passed as two
separate variables.

I think the bigger issue is that simpling sending a PUT command along with
the filenames is not going to send the file to the server. Check out the
FTPClient.java source and look at the _storeFile method. You'll see
everything else that needs to be done to actually store a file.

- Original Message - 
From: "Kevin Dougan" 
To: 
Sent: Tuesday, June 02, 2009 8:38 AM
Subject: RE: Question about FTPClient.sendCommand()



Hi and thanks for your reply. I'll try and give an example to illustrate...



Let's say there's a file that contains the following lines:

   CWD /home/sampleuser/

   PUT localfile.txt remotefile.txt


I am building a Java Class that will be "dumb", in the sense that it will
just open the file (after connecting to the FTP Server using some other
properties), and issue the commands it finds in that file. The idea is that
the caller can dynamically build a file of commands, and the program does
not have to parse them individually and decide what they are, the program
can simply pass them along to the FTP Server.



Therefore, I was thinking that I could use the FTPClient.sendCommand()
method to simple forward those commands, but it is not working.



I do NOT want to do the following:

...read line from file: PUT localfile.txt remotefile.txt

...decide which API method to call: if (line.startsWith("PUT"))
client.storeFile(remoteFile, localFile); else if
(line.statrsWith("GET"))...etc, etc



However, I am trying to do something more simple, like the following:

...read line from file: PUT localfile.txt remotefile.txt

...pass the command along

...read next line from file: : : :

...pass the command along: : : :

...etc, etc



Thanks!
Kevin
kevindou...@hotmail.com


> From: sc...@camsbycbs.com
> To: user@commons.apache.org
> Subject: Re: Question about FTPClient.sendCommand()
> Date: Tue, 2 Jun 2009 08:29:55 -0400
>
> I'm not sure if I understand what you're trying to accomplish. Are you
> sending FTP commands to the FTP server? If so, what command? Or are you
> trying to send operating system shell script commands? The FTP server is
> only going to accept commands it understands and supports, which is not
the
> same as OS shell scripts.
>
> - Original Message - 
> From: "Kevin Dougan" 
> To: 
> Sent: Tuesday, June 02, 2009 7:14 AM
> Subject: Question about FTPClient.sendCommand()
>
>
>
> Greetings!
>
> I have been searching around a lot, trying to figure out how to properly
use
> the FTPClient.sendCommand() API method, but to no avail! Perhaps someone
> here can answer my question very quickly...?
>
> Basically, I want to implement a "dumb" FTP class who handles "batch
> processing". I thought I could just read lines from a file, and then pass
> them through to an FTP Server using the sendCommand() method, but it
always
> replies with "command not understood".
>
> Am I totally off track with what I want to do here? Am I using the API
> method incorrectly or for the wrong purpose?
>
> I am trying to avoid parsing every command, doing a String compare on each
> word, and then trying to match it against a specific API method
> (storeFile(), retrieveFile(), etc.), depending on each String I
parse...big,
> long IF blocks are ugly!
>
> Thanks!
> Kevin
> kevindou...@hotmail.com
>
>
> _
> Attention all humans. We are your photos. Free us.
> http://go.microsoft.com/?linkid=9666046
>
>
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>

_
We are your photos. Share us now with Windows Live Photos.
http://go.microsoft.com/?linkid=9666047


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



Re: Question about FTPClient.sendCommand()

2009-06-02 Thread Steve Cole
I'm not sure if I understand what you're trying to accomplish. Are you
sending FTP commands to the FTP server? If so, what command? Or are you
trying  to send operating system shell script commands? The FTP server is
only going to accept commands it understands and supports, which is not the
same as OS shell scripts.

- Original Message - 
From: "Kevin Dougan" 
To: 
Sent: Tuesday, June 02, 2009 7:14 AM
Subject: Question about FTPClient.sendCommand()



Greetings!

I have been searching around a lot, trying to figure out how to properly use
the FTPClient.sendCommand() API method, but to no avail! Perhaps someone
here can answer my question very quickly...?

Basically, I want to implement a "dumb" FTP class who handles "batch
processing". I thought I could just read lines from a file, and then pass
them through to an FTP Server using the sendCommand() method, but it always
replies with "command not understood".

Am I totally off track with what I want to do here? Am I using the API
method incorrectly or for the wrong purpose?

I am trying to avoid parsing every command, doing a String compare on each
word, and then trying to match it against a specific API method
(storeFile(), retrieveFile(), etc.), depending on each String I parse...big,
long IF blocks are ugly!

Thanks!
Kevin
kevindou...@hotmail.com


_
Attention all humans. We are your photos. Free us.
http://go.microsoft.com/?linkid=9666046


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



Re: Read time out issue

2009-05-26 Thread Steve Cole
Need to see the code.

- Original Message - 
From: "Siddharth Godbole" 
To: 
Sent: Monday, May 25, 2009 1:28 AM
Subject: Read time out issue


> Hi,
>
>I am using commons net version of 1.4.1 for connection with a telnet
> server. I have set SO Timeout as 30 seconds. This is what is happening
> currently:
>First request sent to device is always successful. If i send another
> request within 30 seconds of seconds request, request is send successfully
> but while reading response, I get Socket read timeout immediately. However
> if my requests are spaced by 30 seconds, both requests are successful. I
am
> running my client application on Solaris machine. Telnet server is also
> running on Solaris.
>
>   Can someone tell me what could be wrong?
>
> Thanks,
> Sid
>


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



Re: [commons-net] FTPClient setReceiveBufferSize() setSendBufferSize()

2009-04-22 Thread Steve Cole
Download the source, modify the SocketClient.connect() method and use the
setReceiveBufferSize() and setSendBufferSize() methods and see if it gives
you results you want.

Have you tried using the FTPClient.setBufferSize() method, which sets the
buffersize of the BufferedInputStream used for the retrieveFile() method and
BufferedOutstream used for the storeFile() method?

- Original Message - 
From: 
To: 
Sent: Wednesday, April 22, 2009 3:01 PM
Subject: [commons-net] FTPClient setReceiveBufferSize() setSendBufferSize()


> I have an ftp connection that would greatly benefit from having very large
TCP/IP window sizes (1MB). I'm having trouble figuring out how to implement
this using the standard FTPClient. What's the intended usage of
setReceiveBufferSize() and setSendBufferSize(), which are inherited from the
SocketClient?
>
> From what I understand, setReceiveBufferSize() must be set prior to
binding to the socket? However, if these methods are called prior to
FTPClient.connect(), then this socket object isn't initialized. After
FTPClient.connect(), is it too late?
>
> Any insight into configuring the FTPClient to configure these window sizes
is greatly appreciated.
>
> Thanks,
>
> Phil
>


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



Re: IOExceptionjavax.net.ssl.SSLException: Unexpected end of handshake data

2009-04-20 Thread Steve Cole
Verify the server supports explicit SSL, not implicit.

Verify you should be setting the protocol to SSL instead of the default TLS.

Also, what version of commons-net are you using, 1.4.1 or 2.0?

- Original Message - 
From: "Chetan" 
To: "Commons Users List" 
Sent: Sunday, April 19, 2009 11:15 PM
Subject: Re: IOExceptionjavax.net.ssl.SSLException: Unexpected end of
handshake data


Hi Steve,

The server does not require the client to use certificate, Just using
username and password.
The certificate is at the server level.

Thanks
Chetan



Imagination is more important than knowledge.
Take care,
Cheers,
Chetan




________
From: Steve Cole 
To: Commons Users List 
Sent: Friday, 17 April, 2009 20:45:15
Subject: Re: IOExceptionjavax.net.ssl.SSLException: Unexpected end of
handshake data

Does the server require the client to use a certificate for authentication?
If so, are you setting the FTPSClient KeyManager using a keystore that
contains the correct signed certificate?

- Original Message - 
From: "Chetan" 
To: 
Sent: Thursday, April 16, 2009 9:49 PM
Subject: IOExceptionjavax.net.ssl.SSLException: Unexpected end of handshake
data


Hi,

I'm trying to make a ftps connection to a server using apache's ftps client,
but getting a expection when trying to make the connection.

IOExceptionjavax.net.ssl.SSLException: Unexpected end of handshake
datajavax.net.ssl.SSLException: Unexpected end of handshake data

Can someone help with this.

Here is the expection

Trying to connect
ftps client created
Just before connectIOExceptionjavax.net.ssl.SSLException: Unexpected end of
handshake datajavax.net.ssl.SSLException
at com.sun.net.ssl.internal.ssl.HandshakeInStream.read(Unknown Source)
at
com.sun.net.ssl.internal.ssl.HandshakeMessage$CertificateMsg.(Unknown
Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown
Source)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown
Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at org.apache.commons.net.ftp.FTPSClient.sslNegotiation(
at org.apache.commons.net.ftp.FTPSClient._connectAction_(
at org.apache.commons.net.SocketClient.connect(
at com.accenture.ftps.trail.FtpsTrailClass.main(: Unexpected end of
handshake
dataFTPSClient.java:240)FTPSClient.java:171)SocketClient.java:178)FtpsTrailC
lass.java:35)

here is the code

int reply;
System.out.println("Trying to connect");
FTPSClient ftps = new FTPSClient("SSL");

System.out.println("ftps client created");

//ftps.setAuthValue("SSL");
System.out.println("Just before connect");

ftps.connect("X",21);

System.out.println("Connected");

reply = ftps.getReplyCode();

if (!FTPReply.isPositiveCompletion(reply))
{
ftps.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
//ftps.setDefaultTimeout(1000);
//ftps.enterRemotePassiveMode();

System.out.println("Before login");
ftps.login("","");
System.out.println("Connected to server");

Thanks in advance
Chetan




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




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



Re: IOExceptionjavax.net.ssl.SSLException: Unexpected end of handshake data

2009-04-17 Thread Steve Cole
Does the server require the client to use a certificate for authentication?
If so, are you setting the FTPSClient KeyManager using a keystore that
contains the correct signed certificate?

- Original Message - 
From: "Chetan" 
To: 
Sent: Thursday, April 16, 2009 9:49 PM
Subject: IOExceptionjavax.net.ssl.SSLException: Unexpected end of handshake
data


Hi,

I'm trying to make a ftps connection to a server using apache's ftps client,
but getting a expection when trying to make the connection.

IOExceptionjavax.net.ssl.SSLException: Unexpected end of handshake
datajavax.net.ssl.SSLException: Unexpected end of handshake data

Can someone help with this.

Here is the expection

Trying to connect
ftps client created
Just before connectIOExceptionjavax.net.ssl.SSLException: Unexpected end of
handshake datajavax.net.ssl.SSLException
at com.sun.net.ssl.internal.ssl.HandshakeInStream.read(Unknown Source)
at
com.sun.net.ssl.internal.ssl.HandshakeMessage$CertificateMsg.(Unknown
Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown
Source)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown
Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at org.apache.commons.net.ftp.FTPSClient.sslNegotiation(
at org.apache.commons.net.ftp.FTPSClient._connectAction_(
at org.apache.commons.net.SocketClient.connect(
at com.accenture.ftps.trail.FtpsTrailClass.main(: Unexpected end of
handshake
dataFTPSClient.java:240)FTPSClient.java:171)SocketClient.java:178)FtpsTrailC
lass.java:35)

here is the code

int reply;
System.out.println("Trying to connect");
FTPSClient ftps = new FTPSClient("SSL");

System.out.println("ftps client created");

//ftps.setAuthValue("SSL");
System.out.println("Just before connect");

ftps.connect("X",21);

System.out.println("Connected");

reply = ftps.getReplyCode();

if (!FTPReply.isPositiveCompletion(reply))
{
ftps.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
//ftps.setDefaultTimeout(1000);
//ftps.enterRemotePassiveMode();

System.out.println("Before login");
ftps.login("","");
System.out.println("Connected to server");

Thanks in advance
Chetan




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



Re: Client authentication

2009-04-09 Thread Steve Cole
FTPSClient will automatically accept the server certificate. If you want
FTPSClient to verify the identity of the server, to prevent being redirected
and connecting to the wrong server, you need to create and load a
TrustManager using the keystore that contains the server's certificate along
with any others in the chain. If the server requires the client to present a
certificate for authentication, you need to create and load a KeyManager
using the keystore that contains the certificate issued to you by the
issuing authority on the server's certificate.

FTPSExample.java is a basic example, but it doesn't cover setting
TrustManager or KeyManager

- Original Message - 
From: "Chetan" 
To: 
Sent: Thursday, April 09, 2009 5:51 AM
Subject: Client authentication


Hi,

I am facing some problems when trying to make a ftps connection using apache
ftps client.
Can some one let me know how to accept the server certification and complete
the connection.




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



Re: org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication

2009-04-08 Thread Steve Cole
Try port 21. That or maybe the server is only configured for implicit ssl.

- Original Message - 
From: "Chetan" 
To: 
Sent: Tuesday, April 07, 2009 10:59 PM
Subject: org.apache.commons.net.ftp.FTPConnectionClosedException: Connection
closed without indication



Hi,

I am trying to establish a FTPS connection to a server using username and
password.
I am getting

Just before connection
Could not connect to server.
org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed
without indication.
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:297)
at org.apache.commons.net.ftp.FTP._connectAction_(FTP.java:364)
at org.apache.commons.net.ftp.FTPClient._connectAction_(FTPClient.java:540)
at
org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:167)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:178)
at com.accenture.ftps.trail.FTPSExample.main(FTPSExample.java:93)

When I try to make the connection.

Here is the code snippet that I am using

ftps = new FTPSClient(protocol,false);

ftps.addProtocolCommandListener(new PrintCommandListener(new
PrintWriter(System.out)));

try
{
int reply;
System.out.println("Just before connection");
ftps.connect(server,990);
System.out.println("Connected to " + server + ".");


Here is the filezilla message

220-FileZilla Server version 0.9.31 beta
220-written by Tim Kosse (tim.ko...@gmx.de)
220 Please visit http://sourceforge.net/projects/filezilla/
421 Login time exceeded. Closing control connection.

Can some one help.

Thanks
Chetan




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



Re: how to use http proxy to connect a ftp

2009-03-25 Thread Steve Cole
This may be
helpful...http://marc.info/?l=jakarta-commons-user&m=107877944806547&w=2


- Original Message - 
From: "王巍巍" 
To: 
Sent: Tuesday, March 24, 2009 9:47 PM
Subject: how to use http proxy to connect a ftp


I used apache common net FTPClient to connect a ftp server. I used a http
proxy as I'm in a campus network. However, the FTPClient use socket
to connect the remote ftp server and the connection only allow a socks
proxy. However, when i used flashfxp and set the http proxy the same as in
my program, flashfxp connected to the ftp server successfully

miserable? Could anybody tell me why and how to conquer it?

-- 
王巍巍(Weiwei Wang)
Department of Computer Science
Gulou Campus of Nanjing University
Nanjing, P.R.China, 210093

Mobile: 86-13913310569
MSN: ww.wang...@gmail.com
Homepage: http://cs.nju.edu.cn/rl/weiweiwang



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



Re: [Commons NET]

2009-03-05 Thread Steve Cole
I think you need to call the FTPClient completePendingCommand() method.

Here's the example from API documentation...

For example, 
 InputStream input;
 OutputStream output;
 input  = new FileInputStream("foobaz.txt");
 output = ftp.storeFileStream("foobar.txt")
 if(!FTPReply.isPositiveIntermediate(ftp.getReplyCode())) {
 input.close();
 output.close();
 ftp.logout();
 ftp.disconnect();
 System.err.println("File transfer failed.");
 System.exit(1);
 }
 Util.copyStream(input, output);
 input.close();
 output.close();
 // Must call completePendingCommand() to finish command.
 if(!ftp.completePendingCommand()) {
 ftp.logout();
 ftp.disconnect();
 System.err.println("File transfer failed.");
 System.exit(1);
 }
- Original Message - 
From: "Ward" 
To: "Commons Users List" 
Sent: Thursday, March 05, 2009 9:44 AM
Subject: [Commons NET]


> Hi,
> 
> I'm using the Apache Commons NET library to ftp some files to a server.
> I use the storeFileStream() method of FTPClient so I can write on the 
> OutputStream and keep track of the progress during the upload
> This is (a summary of) the code:
> 
> File file = File("location of file");
> FileInputStream fis = new FileInputStream(file);
> FTPClient ftpClient = new FTPClent();
> ftpClient.connect(server-name);
> ftpClient.login(user,pass);
> ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
> OutputStream os = ftpClient.storeFileStream(file.getName());
> byte buf[] = new byte[1024];
> int len;
> long totalLength = file.length();
> long bytesRead = 0;
> long percent;
> while ((len = fis.read(buf)) > 0) {
>  os.write(buf, 0, len);
>  bytesRead += len;
>  percent = (100 * bytesRead / totalLength);
> }
> fis.close();
> os.close();
> ftpClient.disconnect();
> 
> This seems to work fine: files get uploaded.
> But when I take a closer look at the uploaded files, I notice they 
> aren't uploaded completely.
> The uploaded files are all shorter than the original files on my disk
> The difference is alway around the 59-60kb
> What could be the reason for that?
> Is there something wrong with the copy-ing-structure I use between the 2 
> streams?
> 
> Thanks for anwering
> 
> Ward
> 
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
> 
> 


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



Re: org.apache.commons.net.ftp.FTPSClient question

2009-02-05 Thread Steve Cole
I figured it out, but here's what I did for anyone else this may help...

  KeyStore keyStore = KeyStore.getInstance(keyStoreType,
keyStoreProvider);
  keyStore.load(new
FileInputStream(keyStoreFilename),keyStorePassword.toCharArray());
  KeyManagerFactory keyManagerFactory =
KeyManagerFactory.getInstance(keyStoreAlgorithm);
  keyManagerFactory.init(keyStore,keyStorePassword.toCharArray());
  KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();
  if (keyManagers.length == 0){
throw new Exception("No KeyManager found");
  }else if (keyManagers.length > 1){
// I built the keystore and I'm only expecting 1 KeyManager,
// your implementation may differ
throw new Exception(keyManagers.length + " KeyManagers found.
Expected 1");
  }
  ftpsClient.setKeyManager(keyManagers[0]);


- Original Message - 
From: "Steve Cole" 
To: 
Sent: Tuesday, February 03, 2009 4:19 PM
Subject: org.apache.commons.net.ftp.FTPSClient question


How to do I set the keystore used for client and server certifcate
authentication? Can I just set these System properties or do I need actually
set the KeyManager and TrustManager in FTPSClient?

System.setProperty("javax.net.ssl.trustStore",trustStore);
System.setProperty("javax.net.ssl.trustStoreType",trustStoreType);
System.setProperty("javax.net.ssl.trustStorePassword",trustStorePassword);

System.setProperty("javax.net.ssl.keyStore",keyStore);
System.setProperty("javax.net.ssl.keyStoreType",keyStoreType);
System.setProperty("javax.net.ssl.keyStorePassword",keyStorePassword);

Thanks,

Steve




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



org.apache.commons.net.ftp.FTPSClient question

2009-02-03 Thread Steve Cole
How to do I set the keystore used for client and server certifcate 
authentication? Can I just set these System properties or do I need actually 
set the KeyManager and TrustManager in FTPSClient?

System.setProperty("javax.net.ssl.trustStore",trustStore);
System.setProperty("javax.net.ssl.trustStoreType",trustStoreType);
System.setProperty("javax.net.ssl.trustStorePassword",trustStorePassword);

System.setProperty("javax.net.ssl.keyStore",keyStore);
System.setProperty("javax.net.ssl.keyStoreType",keyStoreType);
System.setProperty("javax.net.ssl.keyStorePassword",keyStorePassword);

Thanks,

Steve