Hey

I have a FTP server with this


ftp://192.168.100.2/folder/

And I have something like


anotherfolder:
afolderinsidethatone:
file1.bin
file2.bin
file.txt

I want to pass all of that to the ftp server so it takes this form:


ftp://192.168.100.2/folder/anotherfolder/
ftp://192.168.100.2/folder/anotherfolder/afolderinsidethatone/
ftp://192.168.100.2/folder/anotherfolder/afolderinsidethatone/file1.bin
ftp://192.168.100.2/folder/anotherfolder/afolderinsidethatone/file2.bin
ftp://192.168.100.2/folder/anotherfolder/file.txt

I have this code:

public void subidaftp(String ip, String usuario, String pass, String fichero, String directorio)
	{
		FTPClient client = new FTPClient();
		FileInputStream fis = null;
		try 
		{
			client.connect(ip);
			client.login(usuario, pass);
			String filename = fichero;
			fis = new FileInputStream(filename);		
			
			boolean existe=client.changeWorkingDirectory(directorio);
			if (existe==false)
			{
				client.makeDirectory(directorio);
				client.storeFile(filename, fis);
				client.rename(filename, directorio + filename);
			}
			else
			{
				client.storeFile(filename, fis);
				client.rename(filename, directorio + filename);
			}
			client.logout();
									
		} 
		catch (IOException e) 
		{
			System.out.println("ERROR: Ha ocurrido un error ( " +e.getLocalizedMessage()+" )");
		}
		finally
		{
			try
			{
				if (fis!=null)
				{
					fis.close();
				}
				client.disconnect();
			}
			catch (IOException e) 
			{
				System.out.println("ERROR: Ha ocurrido un error al cerrar el fichero ( " +e.getLocalizedMessage()+" )");
			}
		}
	}

And when I call it, there is no error message (so it finds the file I try to load) but It just creates a empty folder, nothing else.


How can I adapt it to just naming a folder and putting everything in the server keeping the structure?

Thanks

What does the FTP server do when your program connects to it and sends it instructions and data? Are there any error messages?

What packages are you classes in? You don't show the import statements for the code.

(Lunch break, in case anyone asks for more code)

What does the FTP server do when your program connects to it and sends it instructions and data? Are there any error messages?

What packages are you classes in? You don't show the import statements for the code.

It creates a folder (the FTP server) with the name of the fichero variable.

The imports were basically give ins, that's why I did not post them.

I left the PC back so I can VNC back to it if it is neccesary but I'm on a phone so....

The imports were basically give ins,

What packages are you using? Where do the classes come from?

What more does the server do or not do? Are there error messages on the server?

What packages are you using? Where do the classes come from?

What more does the server do or not do? Are there error messages on the server?

What I use in order to do the FTP transfers is the Apache commons library.

The server gives no error at all. The server like I mentioned creates a empty folder with the value in the varible of fichero being its name.

Edited 4 Years Ago by riahc3: n/a

Back at work....

package herramientas;


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

import org.apache.commons.net.ftp.FTPClient;

Im currently with those packages and imports.......

Which side do you think the problem is on: client or server?
Can you send one file successfully?
Is the problem only when you try to send more than one file?

Which side do you think the problem is on: client or server?
Can you send one file successfully?
Is the problem only when you try to send more than one file?

I think it is a client side problem as the server correctly makes the folder.
"Yes" but with " " since it creates a folder with the name of the value in the variable fichero.
No, I cant send one. It only (for now) does what is stated above.

If you can't send one, how can you expect to send more than one?
Can you create a test program that can send one file? When you get that to work, then work on sending more than one file.

If you can't send one, how can you expect to send more than one?
Can you create a test program that can send one file? When you get that to work, then work on sending more than one file.

I was hoping that since I could make at least the folder with the filename, I would be able to send a file as normal...

Have you tried doing the FTP commands manually to see how to use them?

I believe I tried in the beginning when I was messing around with this FTP code (way back, 3-5 months ago) tried FTP commands but the server didnt like it, it seems.

BTW, it is running Windows CE if that helps.

Have you looked on the server to see if the file is being written in another location.

Yes and I cant find it anywhere.

Which is strange as no error is given which means the file has been transfered (correct?)

It also replies things like when I use the change current directory command (thru Java and the Apache library) if the folder exists or not.

Im going to sleep and lets see if tommorow at my job I can give you more information.

Edited 4 Years Ago by riahc3: n/a

All of the FTP commands should receive a response with a response code. I don't see in your code where you ever check the response code for error conditions.
What if the server finds a problem or there is an error, what would/should your code do?

All of the FTP commands should receive a response with a response code. I don't see in your code where you ever check the response code for error conditions. What if the server finds a problem or there is an error, what would/should your code do?

The Apache library is ready and prepared for response codes returned from the server so the library would throw a (Java) exception if something went wrong. That's one of the reason that the change working directory returns a boolean.

Today (in 30 mins) I'm going to try to do it in a another project and see how it acts. Let's see if breaking down this program, we can see where the problem is. Ill post when I have the result.


Thank you for your help

Edited 4 Years Ago by riahc3: n/a

In another project (Where I created the same structure) it doesnt work at all.

Using a very sloppy fix :P I was able to do it..........but now I have another problem......


(New thread)

Can you explain what the fix was?

I don't like sloppy fixes so that's why I didn't post it.

On the local drive, I make a copy of the file inside the folder and that copy I transfer to the FTP server which works

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