commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knezevic, Mihael" <m.kneze...@porta.de>
Subject RE: Commons NET
Date Wed, 10 Aug 2005 08:59:52 GMT
i don't know your setup but do you really need to go into remote passive mode and shouldn't
you use then the remoteStore method? only a suggestion as i haven't used it yet and never
worked with remote passive mode.

> -----Original Message-----
> From: Andrew Elcock [mailto:andy@elcock.org] 
> Sent: Tuesday, August 09, 2005 5:34 PM
> To: Jakarta Commons Users List
> Subject: Re: Commons NET
> 
> 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 -
> 
> Andrew
> -------------------
> 
>    public void uploadFile(File f, boolean delete) {
>      try {
> //      mkparentdirs();
>        if (!f.exists())
>          return;
> 
>        FTPClient ftpChannel = getFTPChannel(getSite());
>        try {
> //        try {
> //          ftpChannel.makeDirectory((new 
> File(file)).getParentFile().getPath());
> //        } catch (IOException e) {/* already existed */}
>          FileInputStream fis = new FileInputStream(f);
>          ftpChannel.storeFile(file, fis);
>          fis.close();
> //        ftpChannel.completePendingCommand();
> System.out.print(ftpChannel.getReplyString());
>          /* Don't think we want this in a finally block - may 
> delete all 
> copies! */
>          if (delete)
>            f.delete();
>        } catch (IOException e) {
>          e.printStackTrace();
>        }
>      } catch (Exception io) {
>        io.printStackTrace();
>      }
>    }
> 
>    class OutputStreamWrapper extends FileOutputStream {
>      private File f;
>      public OutputStreamWrapper(File f) throws IOException {
>        super(f);
>        this.f = f;
>      }
> 
>      public void close() throws IOException {
>        super.close();
>        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.connect(site.getRemoteHost());
>          chan.login(site.getRemoteUser(), site.getRemotePassword());
>          chan.enterRemotePassiveMode();
> 
>          channelHash.put(site, chan);
>        } catch (Exception e) {
>          e.printStackTrace();
>          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 [mailto:andy@elcock.org] 
> >>Sent: Monday, August 08, 2005 11:07 AM
> >>To: commons-user@jakarta.apache.org
> >>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.
> >>
> >>Thanks,
> >>Andrew
> >>
> >>------------------------------------------------------------
> ---------
> >>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: 
> commons-user-help@jakarta.apache.org
> >>
> >>
> > 
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: 
> commons-user-help@jakarta.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 

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


Mime
View raw message