commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Elcock <>
Subject Re: Commons NET
Date Tue, 09 Aug 2005 15:34:18 GMT
OK, so when I write to the FTP server with this code nothing appears at 
the other end.

If I use the "completePendingCommand" that is commented out things seem 
to hang.

Please excuse the code.

The upload is invoked when someone closes the output stream on the file 
that we are uploading (by means of OutputStreamWrapper).

Sure I am missing something, thanks -


   public void uploadFile(File f, boolean delete) {
     try {
//      mkparentdirs();
       if (!f.exists())

       FTPClient ftpChannel = getFTPChannel(getSite());
       try {
//        try {
//          ftpChannel.makeDirectory((new 
//        } catch (IOException e) {/* already existed */}
         FileInputStream fis = new FileInputStream(f);
         ftpChannel.storeFile(file, fis);
//        ftpChannel.completePendingCommand();
         /* Don't think we want this in a finally block - may delete all 
copies! */
         if (delete)
       } catch (IOException e) {
     } catch (Exception io) {

   class OutputStreamWrapper extends FileOutputStream {
     private File f;
     public OutputStreamWrapper(File f) throws IOException {
       this.f = f;

     public void close() throws IOException {
       uploadFile(f, true);

   private static Hashtable channelHash = new Hashtable();
   public static FTPClient getFTPChannel(Site site) {
     FTPClient chan = (FTPClient) channelHash.get(site);

     if (chan == null || !chan.isConnected()) {
       try {
         chan = new FTPClient();
         chan.login(site.getRemoteUser(), site.getRemotePassword());

         channelHash.put(site, chan);
       } catch (Exception e) {
         return null;
     return chan;

Knezevic, Mihael wrote:
> if u could describe your problem a bit more than perhaps someone on the list could help
u. just saying that it doesn't work is not very precise. perhaps a code snippet and a precise
description/error message will help us to get u on track.  
>>-----Original Message-----
>>From: Andrew Elcock [] 
>>Sent: Monday, August 08, 2005 11:07 AM
>>Subject: Commons NET
>>I am using much commons code and find it to be excellent and 
>>easy to use 
>>for the main, but have hit a barrier with the NET package.
>>I am using the net code to upload files to an FTP server. Using the 
>>examples and documentation I have a system that can connect, create 
>>folders etc, but fails miserably to actually upload data. Is there a 
>>common error that I have fallen in to the trap of without luck from 
>>archives, or is it unique to me? I can send the code, but did 
>>not want 
>>to pollute the list straight off.
>>To unsubscribe, e-mail:
>>For additional commands, e-mail:
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message