Reputation: 63
i need help in sending request to FTP server for downloading a file... i have written the following code to download a file using HTTP it work successfully but i don't know how to do for a FTP..... as i have used socket for making connection it has to be done through this way just suggest me what will be the format of a request (to send to server) for download a FTP file......
///////////////////////////coding////////////////////////////////////////////////////////
URL url_of_file=new URL("http://fs36.filehippo.com/4281/856e12e1656d480da79ef2b40581f75e/npp.6.2.Installer.exe");
String hostaddress=url_of_file.getHost();
Socket mysocket3 = new java.net.Socket();
//create socket to server for HTTP use port 80 for FTP use 21 //
mysocket3.connect(new InetSocketAddress(hostaddress,80));
OutputStream os = mysocket3.getOutputStream();
int file_size=5860557;
//REQUEST Formate for HTTP ..........//
String getRequest = "GET " + url_of_file + " HTTP/1.1\r\n" +
"Host: "+ hostaddress + "\r\n" +
"Range: bytes=0-"+file_size+" \r\n\r\n";
os.write(getRequest.getBytes("UTF-8"));
os.flush();
InputStream in = mysocket3.getInputStream();
// 2. Recieving the data,..............
Upvotes: 1
Views: 3702
Reputation: 19185
You can use org.apache.commons.net.ftp.FTPClient
FTPClient f = new FTPClient();
f.connect(server);
f.login(username, password);
Upvotes: 0
Reputation: 46768
FTP is a different protocol from HTTP. There is no "GET" request in FTP. In order to understand how the requests and responses look, read the RFC959 FTP specification.
From a Java perspective, you could try org.apache.commons.net.ftp.FTPClient.
Upvotes: 5