Hi everyone.
Im trying to upload a file to an ftp server. I found this code in the internet but its not working for me.
Can anyone please tell me where the error is??
This is my code
import java.io.*;
import org.apache.commons.io.FileUtils;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
public class FtpConnectDemo {
public static void main (String[] args) {
FTPClient client = new FTPClient();
FileInputStream fis = null;
InputStream is = null;
OutputStream os = null;
try {
client.connect("ftp.domain.com");
boolean login = client.login("Anonymous", "");
if (login) {
System.out.println("login sucess....");
client.setFileType(FTP.BINARY_FILE_TYPE);
File from = new File("C:\\ftp\\master.txt");
String filename = "master.txt";
fis = new FileInputStream(from);
boolean store = client.storeFile(filename, fis);
if (store) {
System.out.println("dpat ngstore");
}
else {
System.out.println("d ngstore");
}
String[] names = client.listNames();
for (String name : names) {
System.out.println("Name = " + name);
}
boolean logout = client.logout();
if(logout) {
System.out.println("Logout from FTP Server...");
fis.close();
}
}
else {
System.out.println("Login fail....");
}
}
catch (IOException ioe) {
ioe.printStackTrace();
}
finally {
try {
client.disconnect();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
}
and this is the output
login sucess....
d ngstore
Name = test
Logout from FTP Server...
Any help would be greatly appreciated...