From user-return-23029-apmail-commons-user-archive=commons.apache.org@commons.apache.org Tue Jun 02 14:24:24 2009 Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 94897 invoked from network); 2 Jun 2009 14:24:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 2 Jun 2009 14:24:24 -0000 Received: (qmail 77891 invoked by uid 500); 2 Jun 2009 14:24:35 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 77797 invoked by uid 500); 2 Jun 2009 14:24:34 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 77787 invoked by uid 99); 2 Jun 2009 14:24:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Jun 2009 14:24:34 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of kevindougan@hotmail.com designates 65.54.246.96 as permitted sender) Received: from [65.54.246.96] (HELO bay0-omc1-s24.bay0.hotmail.com) (65.54.246.96) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Jun 2009 14:24:24 +0000 Received: from BAY104-W51 ([65.54.175.151]) by bay0-omc1-s24.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 2 Jun 2009 07:24:04 -0700 Message-ID: Content-Type: multipart/alternative; boundary="_534fd05d-e413-45d2-9070-71c426e05508_" X-Originating-IP: [192.127.94.7] From: Kevin Dougan To: Subject: RE: Question about FTPClient.sendCommand() Date: Tue, 2 Jun 2009 10:24:03 -0400 Importance: Normal In-Reply-To: <004101c9e38d$6297cfe0$7e00005a@steve> References: <000b01c9e37d$d6ccc150$7e00005a@steve> <001901c9e381$3c00edf0$7e00005a@steve> <004101c9e38d$6297cfe0$7e00005a@steve> MIME-Version: 1.0 X-OriginalArrivalTime: 02 Jun 2009 14:24:04.0257 (UTC) FILETIME=[C8071110:01C9E38D] X-Virus-Checked: Checked by ClamAV on apache.org --_534fd05d-e413-45d2-9070-71c426e05508_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable OK=2C I guess I can't take the simple approach after all... :-( =20 Thanks for all the help in figuring this out=2C everyone! :-) Cheers!=20 Kevin=20 KevinDougan@Hotmail.com=20 =20 > From: scole@camsbycbs.com > To: user@commons.apache.org > Subject: Re: Question about FTPClient.sendCommand() > Date: Tue=2C 2 Jun 2009 10:21:13 -0400 >=20 > The sendCommand() does just that. It sends a command to the FTP server=2C= but > you have to understand what a FTP command does. >=20 > Some commands are simple. If you send the command FTPCommand.CWD along wi= th > the directory name=2C the server will change directories. >=20 > Some commands require a more complex series of execution=2C like > FTPCommand.STOR=2C FTPCommand.RETR and FTPCommand.LIST. >=20 > The short answer is you can't simply send a PUT command. PUT is a command > many command line FTP clients understand=2C but the FTP server doesn't > understand PUT. The FTP server undersatands the integer value 14. When yo= u > send command 14=2C the server waits for a properly formatted stream of da= ta > that is the actual file. The client must send the command 14=2C then send= the > actual data. >=20 > Here is what happens when you PUT (store) a file on the server... >=20 > // this is the put methed in MyFTPClient.java class > public boolean put()throws Throwable { > boolean rv =3D true=3B > if (binaryTransfer){ > ftpsClient.setFileType(FTP.BINARY_FILE_TYPE)=3B > }else{ > ftpsClient.setFileType(FTP.ASCII_FILE_TYPE)=3B > } > if (passiveMode){ > ftpsClient.enterLocalPassiveMode()=3B > }else{ > ftpsClient.enterLocalActiveMode()=3B > } > InputStream input=3B > input =3D new FileInputStream(localFilename)=3B > ftpsClient.storeFile(remoteFilename=2C input)=3B > input.close()=3B >=20 > return rv=3B > } >=20 > // this is the storeFile methed in the FTPClient.java class > public boolean storeFile(String remote=2C InputStream local)throws > IOException{ > return __storeFile(FTPCommand.STOR=2C remote=2C local)=3B > } >=20 > // this is the underlying _storeFile methed in the FTPClient.java class > private boolean __storeFile(int command=2C String remote=2C InputStream > local)throws IOException{ > OutputStream output=3B > Socket socket=3B > // tell server you want to STOR a file > // the sendCommand method is called in the _openDataConnection_ > method > if ((socket =3D _openDataConnection_(command=2C remote)) =3D=3D null) > return false=3B > // FTPCommand.STOR sent and server is now waiting for file to get > streamed to it > output =3D new > BufferedOutputStream(socket.getOutputStream()=2CgetBufferSize())=3B > if (__fileType =3D=3D ASCII_FILE_TYPE) > output =3D new ToNetASCIIOutputStream(output)=3B > // Treat everything else as binary for now > try{ > Util.copyStream(local=2C output=2C > getBufferSize()=2CCopyStreamEvent.UNKNOWN_STREAM_SIZE=2C null=2Cfalse)=3B > }catch (IOException e){ > try{ > socket.close()=3B > }catch (IOException f){} > throw e=3B > } > output.close()=3B > socket.close()=3B > return completePendingCommand()=3B > } >=20 > // the sendCommand method is actually called in this method > protected Socket _openDataConnection_(int command=2C String arg) throws > IOException { > Socket socket=3B > if (__dataConnectionMode !=3D ACTIVE_LOCAL_DATA_CONNECTION_MODE && > __dataConnectionMode !=3D PASSIVE_LOCAL_DATA_CONNECTION_MODE) > return null=3B >=20 > if (__dataConnectionMode =3D=3D ACTIVE_LOCAL_DATA_CONNECTION_MODE) { > ServerSocket server=3B > server =3D _serverSocketFactory_.createServerSocket(0=2C 1=2C > getLocalAddress())=3B > if (!FTPReply.isPositiveCompletion(port(getLocalAddress()=2C > server.getLocalPort()))) { > server.close()=3B > return null=3B > } > if ((__restartOffset > 0) && !restart(__restartOffset)) { > server.close()=3B > return null=3B > } > if (!FTPReply.isPositivePreliminary(sendCommand(command=2C arg))) > { > server.close()=3B > return null=3B > } >=20 > // For now=2C 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=2C we really want > // to allow preventing the accept from blocking indefinitely. > if (__dataTimeout >=3D 0) > server.setSoTimeout(__dataTimeout)=3B > try { > socket =3D server.accept()=3B > } finally { > server.close()=3B > } > } > else > { // We must be in PASSIVE_LOCAL_DATA_CONNECTION_MODE >=20 > if (pasv() !=3D FTPReply.ENTERING_PASSIVE_MODE) > return null=3B >=20 > __parsePassiveModeReply((String) > _replyLines.get(_replyLines.size() - 1))=3B >=20 > socket =3D _socketFactory_.createSocket(__passiveHost=2C > __passivePort)=3B > if ((__restartOffset > 0) && !restart(__restartOffset)) > { > socket.close()=3B > return null=3B > } >=20 > if (!FTPReply.isPositivePreliminary(sendCommand(command=2C arg))) > { > socket.close()=3B > return null=3B > } > } >=20 > if (__remoteVerificationEnabled && !verifyRemote(socket)) > { > InetAddress host1=2C host2=3B >=20 > host1 =3D socket.getInetAddress()=3B > host2 =3D getRemoteAddress()=3B >=20 > socket.close()=3B >=20 > throw new IOException( > "Host attempting data connection " + host1.getHostAddress() > + > " is not same as server " + host2.getHostAddress())=3B > } >=20 > if (__dataTimeout >=3D 0) > socket.setSoTimeout(__dataTimeout)=3B >=20 > return socket=3B > } >=20 >=20 >=20 >=20 > ----- Original Message -----=20 > From: "Kevin Dougan" > To: > Sent: Tuesday=2C June 02=2C 2009 9:53 AM > Subject: RE: Question about FTPClient.sendCommand() >=20 >=20 >=20 >=20 >=20 > Yes=2C I saw that specific API method call=2C but I don't really want to > implement a big set of IF THEN clauses in my code...then I just become an > interpreter for the FTP specification. >=20 >=20 >=20 > Maybe I should be asking a different question=2C like what is sendCommand= () > used for in the first place? >=20 >=20 > Maybe it's not possible to do what I want to do=2C and I WILL have to > String-compare everything I read in=2C and use an IF THEN block to call t= he > various API methods=2C as I encounter different keywords (i.e. re-impleme= nt > the wheel)... >=20 >=20 > Thanks! > Kevin > KevinDougan@Hotmail.com >=20 >=20 > > From: scole@camsbycbs.com > > To: user@commons.apache.org > > Subject: Re: Question about FTPClient.sendCommand() > > Date: Tue=2C 2 Jun 2009 08:54:14 -0400 > > > > The sendCommand method requires the command and args to be passed as tw= o > > separate variables. > > > > I think the bigger issue is that simpling sending a PUT command along w= ith > > the filenames is not going to send the file to the server. Check out th= e > > 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 -----=20 > > From: "Kevin Dougan" > > To: > > Sent: Tuesday=2C June 02=2C 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"=2C in the sense that it = will > > just open the file (after connecting to the FTP Server using some other > > properties)=2C and issue the commands it finds in that file. The idea i= s > that > > the caller can dynamically build a file of commands=2C and the program = does > > not have to parse them individually and decide what they are=2C the pro= gram > > can simply pass them along to the FTP Server. > > > > > > > > Therefore=2C I was thinking that I could use the FTPClient.sendCommand(= ) > > method to simple forward those commands=2C 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=2C localFile)=3B else if > > (line.statrsWith("GET"))...etc=2C etc > > > > > > > > However=2C I am trying to do something more simple=2C like the followin= g: > > > > ...read line from file: PUT localfile.txt remotefile.txt > > > > ...pass the command along > > > > ...read next line from file: : : : > > > > ...pass the command along: : : : > > > > ...etc=2C etc > > > > > > > > Thanks! > > Kevin > > KevinDougan@Hotmail.com > > > > > > > From: scole@camsbycbs.com > > > To: user@commons.apache.org > > > Subject: Re: Question about FTPClient.sendCommand() > > > Date: Tue=2C 2 Jun 2009 08:29:55 -0400 > > > > > > I'm not sure if I understand what you're trying to accomplish. Are yo= u > > > sending FTP commands to the FTP server? If so=2C 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=2C which is= not > > the > > > same as OS shell scripts. > > > > > > ----- Original Message -----=20 > > > From: "Kevin Dougan" > > > To: > > > Sent: Tuesday=2C June 02=2C 2009 7:14 AM > > > Subject: Question about FTPClient.sendCommand() > > > > > > > > > > > > Greetings! > > > > > > I have been searching around a lot=2C trying to figure out how to pro= perly > > use > > > the FTPClient.sendCommand() API method=2C but to no avail! Perhaps so= meone > > > here can answer my question very quickly...? > > > > > > Basically=2C I want to implement a "dumb" FTP class who handles "batc= h > > > processing". I thought I could just read lines from a file=2C and the= n > pass > > > them through to an FTP Server using the sendCommand() method=2C but i= t > > always > > > replies with "command not understood". > > > > > > Am I totally off track with what I want to do here? Am I using the AP= I > > > method incorrectly or for the wrong purpose? > > > > > > I am trying to avoid parsing every command=2C doing a String compare = on > each > > > word=2C and then trying to match it against a specific API method > > > (storeFile()=2C retrieveFile()=2C etc.)=2C depending on each String I > > parse...big=2C > > > long IF blocks are ugly! > > > > > > Thanks! > > > Kevin > > > KevinDougan@Hotmail.com > > > > > > > > > _________________________________________________________________ > > > Attention all humans. We are your photos. Free us. > > > http://go.microsoft.com/?linkid=3D9666046 > > > > > > > > > --------------------------------------------------------------------- > > > To unsubscribe=2C e-mail: user-unsubscribe@commons.apache.org > > > For additional commands=2C e-mail: user-help@commons.apache.org > > > > > > > _________________________________________________________________ > > We are your photos. Share us now with Windows Live Photos. > > http://go.microsoft.com/?linkid=3D9666047 > > > > > > --------------------------------------------------------------------- > > To unsubscribe=2C e-mail: user-unsubscribe@commons.apache.org > > For additional commands=2C e-mail: user-help@commons.apache.org > > >=20 > _________________________________________________________________ > We are your photos. Share us now with Windows Live Photos. > http://go.microsoft.com/?linkid=3D9666047 >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe=2C e-mail: user-unsubscribe@commons.apache.org > For additional commands=2C e-mail: user-help@commons.apache.org >=20 _________________________________________________________________ Internet explorer 8 lets you browse the web faster. http://go.microsoft.com/?linkid=3D9655582= --_534fd05d-e413-45d2-9070-71c426e05508_--