Home
Back
Classi Java


FTP Client

import java.io.File;
   import java.io.FileInputStream;
   import java.io.IOException;
   import sun.net.TelnetOutputStream;
   import sun.net.ftp.FtpClient;
 
public class FTP {
     public FTP() throws IOException {
     String fromFile = "d:\\Entrate-Uscite.ods";
     String toFile = "Entrate-Uscite.ods";
     FileInputStream is = null;
     File file_in = null;
     TelnetOutputStream os = null;
     FtpClient myFtp = null;
     String id = "";
     String pw = "";
   
 try {
     myFtp = new FtpClient();
     myFtp.openServer("better.altervista.org");
     myFtp.login(id, pw);
     myFtp.binary();
 os=(TelnetOutputStream) myFtp.put(toFile);
     file_in= new File(fromFile);
     is= new FileInputStream(file_in);
     byte[] bytes = new byte[(int)file_in.length()];
     int c;
     int total_bytes=0;
     while((c=is.read(bytes)) !=-1)
     {
     total_bytes +=c;
     os.write(bytes,0,c);
     System.out.println(" c value "+ c);
     }
     is.close();
     os.close();
     System.out.println("int " + myFtp.readServerResponse());
     }
     catch (java.io.IOException e) {
     e.printStackTrace();
 }
 } //end PutTheFile
   
 public static void main(String[] args) {
     FTP fTP;
     try {
     fTP = new FTP();
     } catch (IOException e) {
     // TODO
     }
     
	}
     
}