I posted this several days to Sun's forum but cannot seem to get an answer. Can anyone here give me some help? Thanks.
I'm using exec() to run an ftp session with a script. I'm trying to capture the output of the script. I've found many previous topics about this but have yet to get it to work. The output when run manually is:
C:\Temp\Java>ftp -s:c:\\temp\java\\upload.txt 192.168.1.9
Connected to 192.168.1.9.
220 Service Ready for new User
User (192.168.1.9none)):
331 Password Needed for Login
230 User jpifer Logged in Successfully
ftp>
ftp>
ftp> cd /ghost/ghost/images
250 Directory successfully changed to "/ghost/ghost/images"
ftp>
ftp> lcd c:\temp\java
Local directory now C:\temp\Java.
ftp>
ftp> put bugsbunny.zip
200 PORT Command OK
150 Opening data connection
226 Transfer Complete
ftp: 370420 bytes sent in 0.04Seconds 9260.50Kbytes/sec.
ftp>
ftp> close
221 Closing Session
ftp>
ftp> bye
When run by any of the three types of code I get this:
C:\Temp\Java>java DBCopy
User (192.168.1.9none)): Local directory now C:\temp\Java.
cd /ghost/ghost/images
lcd c:\temp\java
put bugsbunny.zip
close
bye
Below are the three different ways I've tried to capture the data. Anyone give me a hand? I'd like to retrieve it just how it looks when running it manually.
Thanks,
James
public void ftpconnection2() //send file using ftp
{
try
{
Runtime r = Runtime.getRuntime();
Process proc = r.exec("ftp -s:" + DBCopyPath + "\\upload.txt " + ftpServer);
int inp;
String s="";
while ((inp = proc.getInputStream().read()) != -1)
{
s+=(char)inp;
/*System.out.write(inp);this is printing the needed thing on my screen */
}
System.out.println("done \n"
System.out.println(s);
/* This is printing some garbage like 1222232323 etc */
int err;
proc.waitFor();
}catch(Exception e)
{System.out.println("Error"+e);}
}
///////////////
/*
Process p = null;
Runtime r = Runtime.getRuntime();
System.out.println("Run the process"
p = r.exec("ftp -s:c:\\temp\\java\\upload.txt 192.168.1.9"
InputStream iStream = p.getInputStream();
InputStreamReader isReader = new InputStreamReader( iStream );
BufferedReader iReader = new BufferedReader( isReader );
String input = null;
System.out.println( "Standard output : " );
while( ( input = iReader.readLine() ) != null )
{
System.out.println( input );
} } catch (Exception e)
{
System.out.println("Problem with running ftp "+e.getMessage());
}
*/
///////////////////////
/* InputStream in = (Runtime.getRuntime().exec("ftp -s:c:\\temp\\java\\upload.txt 192.168.1.9").getInputStream();
byte[] arreglo= new byte[200];
int cantidad = in.read(arreglo);
System.out.println(new String(arreglo,0,cantidad));
} catch (IOException ioe){System.out.println(ioe.getMessage());}
*/
/////////////////
I'm using exec() to run an ftp session with a script. I'm trying to capture the output of the script. I've found many previous topics about this but have yet to get it to work. The output when run manually is:
C:\Temp\Java>ftp -s:c:\\temp\java\\upload.txt 192.168.1.9
Connected to 192.168.1.9.
220 Service Ready for new User
User (192.168.1.9none)):
331 Password Needed for Login
230 User jpifer Logged in Successfully
ftp>
ftp>
ftp> cd /ghost/ghost/images
250 Directory successfully changed to "/ghost/ghost/images"
ftp>
ftp> lcd c:\temp\java
Local directory now C:\temp\Java.
ftp>
ftp> put bugsbunny.zip
200 PORT Command OK
150 Opening data connection
226 Transfer Complete
ftp: 370420 bytes sent in 0.04Seconds 9260.50Kbytes/sec.
ftp>
ftp> close
221 Closing Session
ftp>
ftp> bye
When run by any of the three types of code I get this:
C:\Temp\Java>java DBCopy
User (192.168.1.9none)): Local directory now C:\temp\Java.
cd /ghost/ghost/images
lcd c:\temp\java
put bugsbunny.zip
close
bye
Below are the three different ways I've tried to capture the data. Anyone give me a hand? I'd like to retrieve it just how it looks when running it manually.
Thanks,
James
public void ftpconnection2() //send file using ftp
{
try
{
Runtime r = Runtime.getRuntime();
Process proc = r.exec("ftp -s:" + DBCopyPath + "\\upload.txt " + ftpServer);
int inp;
String s="";
while ((inp = proc.getInputStream().read()) != -1)
{
s+=(char)inp;
/*System.out.write(inp);this is printing the needed thing on my screen */
}
System.out.println("done \n"
System.out.println(s);
/* This is printing some garbage like 1222232323 etc */
int err;
proc.waitFor();
}catch(Exception e)
{System.out.println("Error"+e);}
}
///////////////
/*
Process p = null;
Runtime r = Runtime.getRuntime();
System.out.println("Run the process"
p = r.exec("ftp -s:c:\\temp\\java\\upload.txt 192.168.1.9"
InputStream iStream = p.getInputStream();
InputStreamReader isReader = new InputStreamReader( iStream );
BufferedReader iReader = new BufferedReader( isReader );
String input = null;
System.out.println( "Standard output : " );
while( ( input = iReader.readLine() ) != null )
{
System.out.println( input );
} } catch (Exception e)
{
System.out.println("Problem with running ftp "+e.getMessage());
}
*/
///////////////////////
/* InputStream in = (Runtime.getRuntime().exec("ftp -s:c:\\temp\\java\\upload.txt 192.168.1.9").getInputStream();
byte[] arreglo= new byte[200];
int cantidad = in.read(arreglo);
System.out.println(new String(arreglo,0,cantidad));
} catch (IOException ioe){System.out.println(ioe.getMessage());}
*/
/////////////////