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...

Edited 6 Years Ago by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

where the error is

Can you show us the error message?
Or explain where the error is?

Have you read the doc for the classes and package you are using?

What status code does the server return?

Just found out that i Anonymous logon has no write permission to the ftp server. Ftp admin changed the setting and codes working.

Thanks for the help anyways (",).

This question has already been answered. Start a new discussion instead.