Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sinchan banerje
Greenhorn
Posts: 7
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a question ?
 
sinchan banerje
Greenhorn
Posts: 7
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends what you mean by causing some problem
 
sinchan banerje
Greenhorn
Posts: 7
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic