Commons NET

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Commons NET

Andrew Elcock
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Commons NET

Knezevic, Mihael
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:[hidden email]]
> Sent: Monday, August 08, 2005 11:07 AM
> To: [hidden email]
> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Commons NET, FTPClient

Karel Tejnora
In reply to this post by Andrew Elcock
Hi,
    I would like to extend FTPClient from Commons/Net to support java.nio.*
First step I did is to implement custom SocketFactory. There are not any
problems.
Every method returns java.net.Socket or java.net.ServerSocket as
SocketChannel.socket()
and ServerSocketChannel.socket().
But problems came in FTPClient class, where I needed refactorize
_openDataConnection_().
The __dataTimeout has only setter not getter.
_openDataConnection_ uses private __pasiveHost, __pasivePort through
private __parsePassiveModeReply()
_relyLines aren't visible to.
So I added public int getDataTimeOut(), public  String getPassiveHost(),
public int getPassiveHost(), protected _popReplyLines() and changed
private __parsePassiveModeReply() to protected _parsePassiveReply().
I don't contribute patch yet, because I have few questions.
do you like it to change this things?
And Im new to svn
I took these steps
svn checkout
http://svn.apache.org/repos/asf/jakarta/commons/proper/net/trunk/
but the build generates  commons-net-1.3.0-dev.jar
Whis url should I take to generate proper diff?

Thx.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Commons NET

Andrew Elcock
In reply to this post by Knezevic, Mihael
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:[hidden email]]
>>Sent: Monday, August 08, 2005 11:07 AM
>>To: [hidden email]
>>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: [hidden email]
>>For additional commands, e-mail: [hidden email]
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Commons NET

Knezevic, Mihael
In reply to this post by Andrew Elcock
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:[hidden email]]
> 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:[hidden email]]
> >>Sent: Monday, August 08, 2005 11:07 AM
> >>To: [hidden email]
> >>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: [hidden email]
> >>For additional commands, e-mail:
> [hidden email]
> >>
> >>
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail:
> [hidden email]
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Commons NET

Andrew Elcock
turning off passive worked, thanks - never thought to do that, as I have
always needed passive on in ftp clients...

Thanks!

Knezevic, Mihael wrote:

> 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:[hidden email]]
>>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:[hidden email]]
>>>>Sent: Monday, August 08, 2005 11:07 AM
>>>>To: [hidden email]
>>>>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: [hidden email]
>>>>For additional commands, e-mail:
>>
>>[hidden email]
>>
>>>>
>>>
>>>
>>---------------------------------------------------------------------
>>
>>>To unsubscribe, e-mail: [hidden email]
>>>For additional commands, e-mail:
>>
>>[hidden email]
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [hidden email]
>>For additional commands, e-mail: [hidden email]
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Commons NET

Knezevic, Mihael
In reply to this post by Andrew Elcock
no problem.

> -----Original Message-----
> From: Andrew Elcock [mailto:[hidden email]]
> Sent: Wednesday, August 10, 2005 2:53 PM
> To: Jakarta Commons Users List
> Subject: Re: Commons NET
>
> turning off passive worked, thanks - never thought to do
> that, as I have
> always needed passive on in ftp clients...
>
> Thanks!
>
> Knezevic, Mihael wrote:
> > 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.
>
<snip>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]