• Post Reply Bookmark Topic Watch Topic
  • New Topic

TelnetProtocolException  RSS feed

 
Maysam Sorkhabi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm running an experiment here wher I try to download a file from an ftp server using the sun.net.ftp.FtpClient package. Here is my code which fails with a TelnetProtocolException: Misplaced CR in input.




Any ideas why this is happening? Besides is there a good and free ftp library out there I can use intead of Sun's? Thanks
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the same thing. The problem appears to be the spaces in the FTP file name:

TelnetInputStream tlis = fc.get("Firefox Setup 1.0rc2.exe"); // FAILS
TelnetInputStream tlis = fc.get("FirefoxSetup1.0rc2.exe"); // OK
TelnetInputStream tlis = fc.get("Firefox%20Setup%201.0rc2.exe"); // OK
 
Maysam Sorkhabi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. But now I'm getting a whole bunch of FileNotFound exceptions. Just how do you handle these filenames with spaces in between....?
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry - I don't have any good answers for you.

You might be able to get it to work by quoting the string ("my name with spaces").

You might also be able to get it to work by ditching "sun.net.ftp.FtpClient" and just writing directly in Java sockets. I doubt the sockets-only program would be much longer (if any).

One other note - Sun discourages people from directly using any of the "sun.*" packages anyway.

I'd consider writing a simple sockets program instead.

Please let us know what you find!

Thanx in advance ... and sorry I couldn't be more help!
 
Maysam Sorkhabi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh no Paul no need to be sorry...you people are the greatest on the net when it comes to java...
anyway...I swicthed to another FTP package developed by the Apache group called 'Jakarta' if I'm not mistaken, and it works pretty good except when I download a '.exe' file, say a program installer, I can't run it...



I can successfully download the file (Mozilla Firefox installer) but after download is complete I cannot run it..weird problem somewhere lol
If you're familiar with the porthole system in Gentoo Linux...I am actually trying to develop a similar mini-system for Windows where you open up this nice little program just enter the name of some software you're looking for...It downloads it, and runs it so you can do the rest (i.e. clicking Next-->Next-->Next until its installed lol). And well as you can see it's not going good...
anyway....thanks for your help!
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just grabbed Apache Jakarta Commons Net, and your program is not using it. You're importing com.enterprisedt.net.ftp.* whereas CommonsNet is org.apache.commons.net.ftp.*. So I guess my only recommendation is to try Commons Net's FTPClient. Clearly, you're already setting the transfer mode to BINARY (unless you have to do it immediately before each get atempt?
 
Maysam Sorkhabi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh my bad...Yeah that code I posted is not using Jakarta's package...sorry about that...As for setting the mode to binary each time a 'get' is performed..I never actually thought about that...Gonna try it sometime....Great idea david! Thank you very much.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're quite welcome. Unfortunately, I think that's a stab in the dark, but it's certainly possible. I would hope that the FTPClient would not keep switching back to TEXT mode every time you changed or listed directories or got a file. Since you don't have the source, though, you'll just have to try it and see.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!