dcsimg
How to implement FTP through an application
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Swapna_Rajaputra
Posted On:   Wednesday, April 11, 2001 04:13 AM

Hi I want to know how we can implement FTP through an application...the application should automatically implement it...here we have to transfer some files from one server to another...now what we are doing is like we are getting all the files which are to be transfered into a text file and doing the transfer part explicitely... the need is that the application itself should get all the details of the files which are to be transfered and internally FTP should also work....and if he files are not transfered properly then the application should try once again lets say after 5 min or so.... we are working on powerbuilder and our backend is oracle...this powerbuilder application should do FTP by itself..the files which are to be transfered will    More>>

Hi
I want to know how we can implement FTP through an application...the application should automatically implement it...here we have to transfer some files from one server to another...now what we are doing is like we are getting all the files which are to be transfered into a text file and doing the transfer part explicitely...
the need is that the application itself should get all the details of the files which are to be transfered and internally FTP should also work....and if he files are not transfered properly then the application should try once again lets say after 5 min or so....
we are working on powerbuilder and our backend is oracle...this powerbuilder application should do FTP by itself..the files which are to be transfered will be dynamic so we cant set how many files and what files we are transfering...
this is real urgent and i will be greatful if i get a reply soon...if i can get atleast a general idea also its fine...it will be more helpful to me if anybody replies with respect to the power builder application..
thanks
Swapna

   <<Less

Re: How to implement FTP through an application

Posted By:   jose_ortuno  
Posted On:   Monday, April 23, 2001 12:24 PM

Hi Swapna,

Here you have a small program which performs a FTP. Unfortunately Sun remove the FTP Package and they do not offer future support to "sun.net.*" package, so be aware. If you have a better way please let me Know.

Hope this helps,

Jose Luis

jortuno@ingedigit.com



//**************************************
// FTP.java

//**************************************

import java.io.*;

import sun.net.ftp.*;

import sun.net.*;


class FTP {

FtpClient ftp;


//----------------------------------------------------------------


public static void main(String args[])
{

new FTP();

}


//----------------------------------------------------------------


public FTP()
{

try
{

System.out.println("Teclear nombre del sitio FTP: ");

String sitio_ftp = leer_linea();


ftp = new FtpClient(sitio_ftp);

ftp.login("ID", "Password");

ftp.binary();


leer_telnet();


traer_archivo();

}


catch (IOException e)
{

System.out.println("Excepcion: " + e);

return;

}

}


//----------------------------------------------------------------


String leer_linea() throws IOException
{

DataInputStream s = new DataInputStream(System.in);

return s.readLine();

}


//----------------------------------------------------------------


void leer_telnet() throws IOException
{

int c;


TelnetInputStream t = ftp.list();


while ((c = t.read()) >= 0)

System.out.print("" + (char) c);


t.close();

}


//----------------------------------------------------------------


void leer_telnet_destino_archivo(String nomb_archivo)
throws IOException
{

int c;


TelnetInputStream t = ftp.get(nomb_archivo);


RandomAccessFile f = new RandomAccessFile(nomb_archivo, "rw");


while ((c = t.read()) >= 0)
{

System.out.print("" + (char) c);

f.writeByte((byte) c);

}


f.close();


t.close();

}


//----------------------------------------------------------------


void traer_archivo() throws IOException
{

while (true)
{

System.out.print("
Teclear nombre de archivo ");

System.out.println("(Presione ESC+Enter para salir):");

String cadena = leer_linea();

if (cadena.charAt(0) == (char) 27)

return;


try
{

if (cadena.startsWith("cd "))
{

System.out.println("Cambiar directorio a <" +
cadena.substring(3) + ">");

ftp.cd(cadena.substring(3));

leer_telnet();

}

else
{

System.out.println("Obteniendo el archivo <" +
cadena + ">");

leer_telnet_destino_archivo(cadena);

break;

}

}

catch (FileNotFoundException e) {

System.out.println("El archivo no se encontró! Vuélva a intentarlo");

}

}

}

}

Re: How to implement FTP through an application

Posted By:   Michael_Wax  
Posted On:   Wednesday, April 11, 2001 07:41 AM

See my other answer. Please try not to submit the same question multiple times.
About | Sitemap | Contact