dcsimg
FTP download from a server!! Urgent.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   girishwar_venkataraman
Posted On:   Wednesday, March 2, 2005 09:54 PM

I wrote a java program to upload file to a server it is working fine. but i am not able to download file from server. Suggest changes in this program that will allow download from the server. package com.test; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.net.SocketException; import org.apache.commons.net.ftp.FTPClient; public class FTPClientUpload { /** * */ public FTPClientUpload() { super(); // TODO Auto-generated constructor stub } public static void main(String[] args) { String host = "abc"; String user = "user"; S   More>>


I wrote a java program to upload file to a server it is working fine. but i am not able to download file from server.
Suggest changes in this program that will allow download from the server.
package com.test;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.SocketException;

import org.apache.commons.net.ftp.FTPClient;
public class FTPClientUpload {

/**
*
*/
public FTPClientUpload() {
super();
// TODO Auto-generated constructor stub
}

public static void main(String[] args) {
String host = "abc";
String user = "user";
String password ="pass";
String targetFile = "PackTest.txt";
String localFile = "C:\New Folder\PackTest.txt";



FTPClient ftp = new FTPClient();
try {
ftp.connect("abc");
ftp.login("user","pass");
ftp.makeDirectory("tester");
ftp.setFileType(FTPClient.ASCII_FILE_TYPE);
ftp.cwd("tester");

OutputStream os = ftp.storeFileStream("Test.txt");
//System.out.println(ftp.completePendingCommand()); // To upload
System.out.println("2....");

FileInputStream is= new FileInputStream("C:\New Folder\PackTest.txt");
int c;
while (true) {
c= is.read();
if (c <= 0) break;
os.write(c);
}
os.close();
is.close();
ftp.disconnect();

System.out.println("Sucessfully uploaded....");
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}    <<Less
About | Sitemap | Contact