commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Norbert Lazzeri" <elno...@gmx.de>
Subject FTPSClient.listNames()
Date Thu, 16 Apr 2009 15:18:41 GMT

Hi,

im new to commons-net. for my company-app i need a ftp via ssl connection  
to upload/retrieve some files

Remote system is UNIX Type: L8

connection works fine, also changing the working directory. however when i  
try to get a file-listening, i only get a null value / empty result-lists.

getReplyString() says: 521 Data connections must be encrypted


i could only find few code-snippets for ftps. here is what ive done (this  
is mixed groovy/java code, but shouldnt be harder to read than usual  
java-code). i hope you guyes can give me some hints how to enable  
encryption:



         def ftps = new FTPSClient();

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

         try {
             int reply;

             ftps.connect(data.server);
             //ftps.enterLocalPassiveMode()
             System.out.println("Connected to " + data.server + ".");

             // After connection attempt, you should check the reply code  
to verify
             // success.
             reply = ftps.replyCode;

             if (!FTPReply.isPositiveCompletion(reply)) {
                 ftps.disconnect();
                 System.err.println("FTP server refused connection.");
                 System.exit(1);
             }
             if (ftps.isConnected()) {
                 try {
                     if (!ftps.login(data.user, data.password)) {
                         ftps.logout();
                         ftps.disconnect();
                         println("user/password not accepted")
                         System.exit(1)
                     } else {
                         println "login successfull"
                         System.out.println("Remote system is " +  
ftps.systemName);
                     }
                 }
                 catch (IOException f) {
                     System.err.println("Could not connect to server.");
                     f.printStackTrace();
                     System.exit(1);
                 }
             }

	    if (!ftps.changeWorkingDirectory(data.userDataDirectory))
                         println "could not change to directory:  
${data.userDataDirectory} "

                     //delete if file allready exists
                     def filelist = ftps.listFiles()  //a ftps.listNames()  
returnes null, listFiles returnes an empty list
                     println ftps.getReplyString()
                     filelist.each {FTPFile f ->
                         if (f != null)
                             if (f.name.equals(resultlist.name))
                                 ftps.deleteFile(resultlist.name)

         } catch (IOException e) {
             System.err.println("Could not connect to server.");
             e.printStackTrace();
             System.exit(1);
         }


system-out:
220 XXXXX
AUTH TLS
234 Proceed with negotiation.
Connected to XXXXX
USER XXXXX
331 Please specify the password.
PASS XXXXX
230 Login successful.
login successfull
SYST
215 UNIX Type: L8
Remote system is UNIX Type: L8
CWD userdata
250 Directory successfully changed.
PASV
227 Entering Passive Mode (194,88,217,30,41,196)
LIST
521 Data connections must be encrypted.
521 Data connections must be encrypted.

PASV
227 Entering Passive Mode (194,88,217,30,77,95)
NLST
521 Data connections must be encrypted.

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


Mime
View raw message