This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Code to dowload Ftp FILE from ftp server (cross platform) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Code to dowload Ftp FILE from ftp server (cross platform) " Watch "Code to dowload Ftp FILE from ftp server (cross platform) " New topic
Author

Code to dowload Ftp FILE from ftp server (cross platform)

sinchan banerje
Greenhorn

Joined: Dec 14, 2011
Posts: 7

Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3416
    
  12
Do you have a question ?


Joanne
sinchan banerje
Greenhorn

Joined: Dec 14, 2011
Posts: 7

yes. In my environment this code is working properly while the server is linux and client is windows.

ut it is causing some problem in other environment. Is there a chance that such a thing can happen due to some environment specific problem. If yes, what they may be?
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

sinchan banerje wrote:ut it is causing some problem in other environment. Is there a chance that such a thing can happen due to some environment specific problem. If yes, what they may be?


Well champ, this statement of yours is very vague. What happens? Is there an exception? Please TellTheDetails.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3416
    
  12
Depends what you mean by causing some problem
sinchan banerje
Greenhorn

Joined: Dec 14, 2011
Posts: 7

Please find the below code:

import org.apache.commons.net.ftp.FTPClient;
import java.io.IOException;
import java.io.FileOutputStream;
import java.net.SocketException;
public class ftpTest {
public static void main(String[] args) throws SocketException, IOException {
FTPClient client = new FTPClient();
FileOutputStream fos = null;
fos = new FileOutputStream("D:/myfile.pdf");
String hostfilename = "/home/injm1/XLMP";
client.connect("nmfinccmdev", 22);
client.login("xxx", "xxx");
client.retrieveFile(hostfilename, fos);
fos.close();
client.disconnect();
}
}

But soon after connect i get an following exception

Exception in thread "main" org.apache.commons.net.MalformedServerReplyException: Could not parse response code.
Server Reply: SSH-1.99-OpenSSH_5.0
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:270)
at org.apache.commons.net.ftp.FTP._connectAction_(FTP.java:321)
at org.apache.commons.net.ftp.FTPClient._connectAction_(FTPClient.java:522)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:162)
at ftpTest.main(ftpTest.java:12)


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

You're using an FTP client to connect to an SSH server. That's not going to work. Either change your port to 21 so you'll actually use the FTP server (if present), or use a different library for SSH handling.

Also, don't post actual login details, as this may encourage some people with bad intentions to login on your system. Replace them with something bogus. I did that for you this time, using "xxx" for both the user name and password.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Code to dowload Ftp FILE from ftp server (cross platform)
 
Similar Threads
pdf getting corrupted while transfering through FTP
Need Expert help with FTP
Reading log files from various unix servers through Java program on windows
FTP Dowload JPG & XML files only... USing com.oroinc.net.ftp.* from FTP server
Problem in connecting to FTP server