Não usa socket não

0 respostas
marciocamurati

E ai !

Por acaso eu estava usando isso agora pouco o código q usei foi este para dar upload de um arquivo, ele nãoo utiliza socket apenas ele e o io para manipular os arquivos:

import java.io.*;
import sun.net.ftp.FtpClient;

class FtpExample {

public static void main(String[] args) {		

	String arquivos_txt[] = { "arquivo1.txt", "arquivo2.txt", "arquivo3.txt", "arquivo4.txt" };
	String host = "ftp.asdas.com";
	String username = "lasdasd";
	String password = "asdasdasd";
	
	for (int total = 0; total < arquivos_txt.length; total++)	{
	
		try {
	
			FtpClient fc;

			String path = "C:\"+arquivos_txt[total];
			String directory = "/www/";
			
			int lastSlash = path.lastIndexOf(''');
			String filename = path.substring(lastSlash+1);
		
			FtpClient client = new FtpClient(host);
			client.login(username, password);
			client.binary();
			client.cd(directory);
		
			FileInputStream criar = new FileInputStream(filename);
			OutputStream  pegar = client.put(filename);
			byte buffer[] = new byte[1000];
			int len;
	
			while( (len = criar.read(buffer)) != -1 ) {
				pegar.write(buffer,0,len);
			}
	
			criar.close();
			pegar.close();
			client.closeServer();

			System.out.println("Finalizado...");
	
		}	catch(Exception e)	{
			System.out.println(e.getMessage());
		}		
	}
	
}

}

Criado 21 de junho de 2004
Respostas 0
Participantes 1