Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Problem with FTP using Java, please help !

Reply
Thread Tools

Problem with FTP using Java, please help !

 
 
tobleron
Guest
Posts: n/a
 
      11-08-2008
Hi, I have code like this :

package ecgterminal3;

import org.apache.commons.net.ftp.FTPClient;

------- blaaa....

FTPClient client = new FTPClient();
FileInputStream fis = null;

try {
client.connect("ftp://140.135.100.180");
client.login("dicom", "dicom");

String thedcmfile = "D:\\NetBeanProject\
\ECGTerminal3\\DICOMfiles\\" + namafile;
fis = new FileInputStream(thedcmfile);

client.storeFile(thedcmfile, fis);
client.logout();
client.disconnect();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}

-----blaaa....

I found error message : java.net.SocketException: Malformed reply from
SOCKS server.

What happened ? What shoud I use for client.connect("ftp://
140.135.100.180"); ? I already used

client.connect("ftp://140.135.100.180");
client.connect("140.135.100.180");
client.connect("localhost");
client.connect("ftp://localhost");
client.connect("ftp.localhost");

But still get the same error. Please advise. Thank you in advance.
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      11-08-2008
On Sat, 8 Nov 2008 03:47:04 -0800 (PST), tobleron <>
wrote, quoted or indirectly quoted someone who said :

>
>I found error message : java.net.SocketException: Malformed reply from
>SOCKS server.


see http://mindprod.com/jgloss/sniffer.html

to watch the message exchanged.

Use an FTP client to watch the messages exchanged to see what they
SHOULD look like.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Your old road is
Rapidly agin'.
Please get out of the new one
If you can't lend your hand
For the times they are a-changin'.
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      11-08-2008
tobleron wrote:
> package ecgterminal3;
>
> import org.apache.commons.net.ftp.FTPClient;
>
> ------- blaaa....
>
> FTPClient client = new FTPClient();
> FileInputStream fis = null;
>
> try {
> client.connect("ftp://140.135.100.180");
> client.login("dicom", "dicom");
>
> String thedcmfile = "D:\\NetBeanProject\
> \ECGTerminal3\\DICOMfiles\\" + namafile;
> fis = new FileInputStream(thedcmfile);
>
> client.storeFile(thedcmfile, fis);
> client.logout();
> client.disconnect();
> fis.close();
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> -----blaaa....
>
> I found error message : java.net.SocketException: Malformed reply from
> SOCKS server.
>
> What happened ? What shoud I use for client.connect("ftp://
> 140.135.100.180"); ? I already used
>
> client.connect("ftp://140.135.100.180");
> client.connect("140.135.100.180");
> client.connect("localhost");
> client.connect("ftp://localhost");
> client.connect("ftp.localhost");
>
> But still get the same error. Please advise. Thank you in advance.


The error say that FtpClient think sit is talking to a SOCKS server
but is not.

Have you set system properties to tell that ?

Arne
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      11-08-2008
tobleron wrote:
>> package ecgterminal3;
>>
>> import org.apache.commons.net.ftp.FTPClient;
>>
>> ------- blaaa....
>>
>> FTPClient client = new FTPClient();
>> FileInputStream fis = null;


Please use reasonable indentation!

OK?

--
Lew
 
Reply With Quote
 
tobleron
Guest
Posts: n/a
 
      11-08-2008
@All,
The problem has been solved. The code can uploads the original file
into FTP server. But, I found that the size of original file and the
uploaded file were different. You can see the files at
www.artikelilmiah.com/twinfiles.zip . If you open these files with hex
editor, you'll find several 0x0d(s) inside the bytes. How come ?

Here is my code :

@Action public void uploadDICOM() {

setVisible(false);
if (processingBox == null) {
JFrame mainFrame = Main.getApplication().getMainFrame();
processingBox = new Processing(mainFrame);
processingBox.setLocationRelativeTo(mainFrame);
}
Main.getApplication().show(processingBox);

FTPClient ftp = new FTPClient();
try
{
String server = "127.0.0.1";
String username="dicom";
String password="dicom";
int reply;
ftp.connect(server);
ftp.login(username, password);

reply = ftp.getReplyCode();

if(!FTPReply.isPositiveCompletion(reply))
{
ftp.disconnect();
setVisible(false);
if (uploadDICOMBox == null) {
JFrame mainFrame =
Main.getApplication().getMainFrame();
uploadDICOMBox = new UploadFailed(mainFrame);
uploadDICOMBox.setLocationRelativeTo(mainFrame);
}
Main.getApplication().show(uploadDICOMBox);
}

File inFile = new File("D:\\NetBeanProject\\ECGTerminal3\
\src\\ecgterminal3\\ToBeUploaded.txt");
BufferedReader br = new BufferedReader(new
FileReader(inFile));
String text2 = null;
while ((text2 = br.readLine()) != null)
{
String[] words = text2.split(";");
try {
FileInputStream inputstream = new
FileInputStream(words[0]);
ftp.storeFile(words[1],inputstream);
inputstream.close();

} catch (IOException e)
{
e.printStackTrace();
}
}
br.close();
ftp.logout();
ftp.disconnect();

processingBox.setVisible(false);
setVisible(false);
if (uploadDICOMBox == null) {
JFrame mainFrame =
Main.getApplication().getMainFrame();
uploadDICOMBox = new UploadDone(mainFrame);
uploadDICOMBox.setLocationRelativeTo(mainFrame);
}
Main.getApplication().show(uploadDICOMBox);
}
catch(IOException e)
{
processingBox.setVisible(false);
setVisible(false);
if (uploadDICOMBox == null) {
JFrame mainFrame =
Main.getApplication().getMainFrame();
uploadDICOMBox = new UploadFailed(mainFrame);
uploadDICOMBox.setLocationRelativeTo(mainFrame);
}
Main.getApplication().show(uploadDICOMBox);
}
}
 
Reply With Quote
 
tobleron
Guest
Posts: n/a
 
      11-08-2008
On Nov 8, 11:59*pm, Lew <no...@lewscanon.com> wrote:
> tobleron wrote:
> >> package ecgterminal3;

>
> >> import org.apache.commons.net.ftp.FTPClient;

>
> >> ------- blaaa....

>
> >> FTPClient client = new FTPClient();
> >> * * * * * * * * FileInputStream fis = null;

>
> Please use reasonable indentation!
>
> OK?
>
> --
> Lew


@Lew
I used normal indentation when I post this. If the result looked
unreasonable indentation, you're better ask Google Forum's engineer
than me.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      11-08-2008
tobleron wrote:
> On Nov 8, 11:59 pm, Lew <no...@lewscanon.com> wrote:
>> tobleron wrote:
>>>> package ecgterminal3;
>>>> import org.apache.commons.net.ftp.FTPClient;
>>>> ------- blaaa....
>>>> FTPClient client = new FTPClient();
>>>> FileInputStream fis = null;

>> Please use reasonable indentation!
>>
>> OK?
>>
>> --
>> Lew

>
> @Lew
> I used normal indentation when I post this. If the result looked
> unreasonable indentation, you're better ask Google Forum's engineer
> than me.


Pitiful. Just use spaces to indent - Google doesn't add spaces to your
indentation.

--
Lew
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      11-08-2008
tobleron wrote:
> @All,
> The problem has been solved. The code can uploads the original file
> into FTP server. But, I found that the size of original file and the
> uploaded file were different. You can see the files at
> www.artikelilmiah.com/twinfiles.zip . If you open these files with hex
> editor, you'll find several 0x0d(s) inside the bytes. How come ?


You used text transfer instead of binary.

--
Lew
 
Reply With Quote
 
Donkey Hottie
Guest
Posts: n/a
 
      11-08-2008
tobleron <> wrote in news:a092e878-934f-45f7-ac46-
:

> @All,
> The problem has been solved. The code can uploads the original file
> into FTP server. But, I found that the size of original file and the
> uploaded file were different. You can see the files at
> www.artikelilmiah.com/twinfiles.zip . If you open these files with hex
> editor, you'll find several 0x0d(s) inside the bytes. How come ?
>


Your file name "ToBeUploaded.txt" ends with ".txt" which makes ftp to
assume it as a text file. Text files have different end-of-line markings on
different operating systems, and ftp tries to convert it to the format of
receiving server.

Your file propably is binary formatted. Whenever ftp sees 0x0a in it, it
converts that to 0x0d,0x0a as you run that ftp on a Windows machine.

Tell the ftp client that your file is binary.

ftp.setFileType(FTP.BINARY_FILE_TYPE);

 
Reply With Quote
 
John B. Matthews
Guest
Posts: n/a
 
      11-08-2008
In article <gf4m8e$9to$>, Lew <> wrote:

> tobleron wrote:
> > On Nov 8, 11:59 pm, Lew <no...@lewscanon.com> wrote:
> >> tobleron wrote:
> >>>> package ecgterminal3;
> >>>> import org.apache.commons.net.ftp.FTPClient;
> >>>> ------- blaaa....
> >>>> FTPClient client = new FTPClient();
> >>>> FileInputStream fis = null;
> >> Please use reasonable indentation!
> >>
> >> OK?

[...]
> > I used normal indentation when I post this. If the result looked
> > unreasonable indentation, you're better ask Google Forum's engineer
> > than me.

>
> Pitiful. Just use spaces to indent - Google doesn't add spaces to
> your indentation.


OP: In addition, please wrap your code to fewer than 80 columns. Most
editors can help with this; if yours doesn't, try this:

<http://pscode.org/twc/>

Also, consider shorter, more focused examples of problems you encounter.
This effort itself often leads to a solution, precluding the need to ask
for help at all:

<http://pscode.org/sscce.html>

As an example, you recently posted over 250 lines of unreadable code,
asking essentially the same question despite a dozen helpful replies:

<http://groups.google.com/group/comp....sg/afc223aa182
5b857?hl=en>

When you have a problem, look for a working example and see how your
code differs. Start here:

<http://java.sun.com/docs/books/tutorial/index.html>
<http://www.java2s.com/Tutorial/Java/CatalogJava.htm>

Also, please trim signatures and irrelevant text.

--
John B. Matthews
trashgod at gmail dot com
http://home.roadrunner.com/~jbmatthews/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Net/FTP to download a file (FTP Error 550) Jeff Miller Ruby 0 03-26-2009 05:50 PM
FTP : Time problem (net/ftp) Vin Raja Ruby 0 06-07-2007 07:47 AM
'Undifined commands' on FTP Server, when using FTP 'put' and 'quit' in Client Asaf Sinai Perl Misc 1 07-04-2006 01:02 PM
Net::FTP problems getting files from Windows FTP server, but not Linux FTP Server. D. Buck Perl Misc 2 06-29-2004 02:05 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments