2004/09/14

Write a Simple Program to Upload a File to FTP Server

download jar from here: http://www.jibble.org/simpleftp/
which named simpleftp.jar

Sample Code:

import org.jibble.simpleftp.SimpleFTP;
import java.io.IOException;
import java.io.File;
import java.io.FileNotFoundException;

public class SimpleFTPTest {
//connection information, including ip, port,
//user name and password
String ip = "10.64.203.69";
int port = 21;
String userName = "test";
String password = "fet";


public void upload() throws FileNotFoundException, IOException {

try {
SimpleFTP ftp = new SimpleFTP();
ftp.connect(ip, port, userName, password);
ftp.ascii();
ftp.cwd(remoteFile);
ftp.stor(new File("C:/odd.dat"));
ftp.disconnect();

}catch (IOException ioe) {
ioe.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) throws IOException {
SimpleFTPTest simpleFTP = new SimpleFTPTest();
simpleFTP.upload();
}
}

No comments: