Problem with FTP using Java, please help !

T

tobleron

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.
 
A

Arne Vajhøj

tobleron said:
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
 
T

tobleron

@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);
}
}
 
T

tobleron

Please use reasonable indentation!

OK?

@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.
 
L

Lew

tobleron said:
@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.
 
L

Lew

tobleron said:
@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.
 
D

Donkey Hottie

@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);
 
J

John B. Matthews

tobleron said:
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.lang.java.programmer/msg/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.
 
A

Arne Vajhøj

tobleron said:
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 ?
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();

Try:

ftp.setFileType(FTPClient.BINARY_FILE_TYPE);

before ftp.storeFile !

Arne
 
T

tobleron

@Matthews
I understand that visitors of my thread are vary. Some are like to see
the particular problem only, some are want to see the whole code to
inspect, some even focus on other thing than the problem that I want
to solved. But thank you for your suggestion anyway.

@All
The problem has been solved. Thank you for your helps. I appreciate.

Thread closed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top