Calling Windows XP FTP Command in java
Hi there!
Need help in calling Windows XP FTP command in java:
executing the FTP command in DOS works well, but when I tried calling it in java using Process and Runtime objects, it successfully transferred the files from remote to my local pc... but I seemed to be stuck with .exec() and cannot continue with the other statements.
I know that I can use eFTPj or Apache Commons Net .. but I have no more time to study it since I have no more time left.
Any idea or suggestion? I badly need your help�
Take care and God bless,
MaDz
Solution:
Better use Apache Commons Net - FTP for greater java support.
Similar Messages
-
How to call windows help files .hlp from Java program
Hai all everybody
How to call windows Help file that is xxx.hlp files from java programs
any help great!!!!
regards
veeruHow about
Runtime.getRuntime().exec("start xxx.hlp"); -
Call an interactive UNIX command from java
Hi,
I want to call a UNIX command from java. When issue the command 'htpasswd -c filename username' on UNIX terminal, it asks for the new password and the then confirmation password again (yeah, unfortunately the htpasswd installed on our system does not allow you proivde the password on the command line. So have to work interactively ). Now, I have written a simple java program RunCommand.java. I am hardcoding the password for the htpasswd command in the file (in the real situation, password will be generated dynamically). I want to issue 'java RunCommand' on the UNIX command line and get back the command prompt without being asked for the password twice. The code is below, but the Outputstream does not work as expected. It always asks for inputs. Any idea? Many thanks.
import java.io.*;
public class RunCommand {
public static void main(String args[]) throws Exception {
String s = null;
try {
String cmd = "htpasswd -c filename username ";
// run a Unix command
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
OutputStream stdOut = p.getOutputStream();
String pswd = "mypassword";
while ((s = stdInput.readLine()) != null) {
s = stdInput.readLine();
stdOut.write(pswd.getBytes());
stdOut.flush();
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
stdOut.close();
stdInput.close();
stdError.close();
System.exit(0);
catch (IOException e) {
System.out.println("exceptions caught: ");
e.printStackTrace();
System.exit(-1);There are only about 9 billion responses a day on how to do this. Use the search feature.
-
Put ftp commands inside Java code?
Hi.
I've no problems with ftp with exec(...), using an external ftp text file containing the ftp commands.
But can I pullthe ftp commands into the Java codes?
The reason is we don't want people accidentally messing around with the ftp commandsyou can also use URLs for FTPing:
* If the client needs to connect to the server through a proxy, this method sets the JVM FTP proxy settings.
* @param proxyHost Host name of proxy.
* @param proxyPort Port number of proxy host.
public void setProxy(String proxyHost, int proxyPort) {
if (proxyHost != null) {
System.getProperties().put("ftpProxySet", "true");
System.getProperties().put("ftpProxyHost", proxyHost);
System.getProperties().put("ftpProxyPort", ""+proxyPort);
}//setProxy()
* Upload a file to a FTP server. A FTP URL is generated with the following syntax:
* <code>ftp://user:password@host:port/urlpath;type=i</code>.
* @param ftpServer FTP server address.
* @param user Optional user name to login.
* @param pwd Optional password for <i>user</i>.
* @param fileName Destination file name on FTP server (with optional preceeding relative path, e.g. one/two/three.txt).
* @param source Source file to upload.
* @throws Exception on error.
public void upload(String ftpServer, String user, String pwd, String fileName, File source) throws MalformedURLException,
IOException {
if (ftpServer != null && fileName != null && source != null) {
StringBuffer sb = new StringBuffer("ftp://");
if (user != null && pwd != null) {
sb.append(user);
sb.append(':');
sb.append(pwd);
sb.append('@');
sb.append(ftpServer);
sb.append('/');
sb.append(fileName);
sb.append(";type=i"); //a=ASCII mode, i=image (binary) mode, d= file directory listing
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
URL url = new URL(sb.toString());
URLConnection urlc = url.openConnection();
bos = new BufferedOutputStream(urlc.getOutputStream());
bis = new BufferedInputStream(new FileInputStream(source.getName()));
int i;
while ((i = bis.read()) != -1) {
bos.write(i);
} finally {
if (bis != null) { try { bis.close(); } catch (IOException ioe) { /* ignore*/ } }
if (bos != null) { try { bos.close(); } catch (IOException ioe) { /* ignore*/ } }
}//upload()
* Download a file from a FTP server. A FTP URL is generated with the following syntax:
* <code>ftp://user:password@host:port/filePath;type=i</code>.
* @param ftpServer FTP server address (with optional port ':<port>').
* @param user Optional user name to login.
* @param pwd Optional password for <i>user</i>.
* @param fileName Name of file to download (with optional preceeding relative path, e.g. one/two/three.txt).
* @param destination Destination file to save.
* @throws Exception on error.
public void download(String ftpServer, String user, String pwd, String fileName, File destination) throws MalformedURLException,
IOException {
if (ftpServer != null && fileName != null && destination != null) {
StringBuffer sb = new StringBuffer("ftp://");
if (user != null && pwd != null) {
sb.append(user);
sb.append(':');
sb.append(pwd);
sb.append('@');
sb.append(ftpServer);
sb.append('/');
sb.append(fileName);
sb.append(";type=i"); //a=ASCII mode, i=image (binary) mode, d= file directory listing
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
URL url = new URL(sb.toString());
URLConnection urlc = url.openConnection();
bis = new BufferedInputStream(urlc.getInputStream());
bos = new BufferedOutputStream(new FileOutputStream(destination.getName()));
int i;
while ((i = bis.read()) != -1) {
bos.write(i);
} finally {
if (bis != null) { try { bis.close(); } catch (IOException ioe) { /* ignore*/ } }
if (bos != null) { try { bos.close(); } catch (IOException ioe) { /* ignore*/ } }
}//download() -
Call Windows COM/DCOM objects from Java on Linux
Hello, is it possible to call COM/DCOM objects running on Windows from Java on Linux machine? Thank you.
I don't know anything about it but it looks like EZ JCom in conjunction with the included Remote Access Service does what you're after. It's not free though.
http://www.ezjcom.com/ -
Calling Window's Dll Functions from Java
Hello Audience,
Is there a way to call Win32/64 based Dynamic-Link-Library functions from Java?
Thanks,
GenKabukiYes.
In general, if you are trying to call functions in an existing dll, you will have to write a "wrapper" dll that meets the java jni interface requires. There are tools around wich purport to generate these for you. Do a google serach; among other tools, you should turn up JACE. -
How to call window programs FTP from oracle 8i
Hi every one
Dear friends
I have to export a small dmp file from onse db server to another db server via our privtare network using ftp. How can i automate this program using pl/sql
I am trying the flow
Server 1
export a table (selected records)
make file name with some convention
ftp the exported fle to Server 2
after successful transfer on server 2
delete exported file
delete table for selected records
Please help
Prashantprashant13 wrote:
Hi every one
Dear friends
I have to export a small dmp file from onse db server to another db server via our privtare network using ftp. How can i automate this program using pl/sql
I am trying the flow
Server 1
export a table (selected records)
make file name with some convention
ftp the exported fle to Server 2
after successful transfer on server 2
delete exported file
delete table for selected records
Please help
PrashantEven if you could (doubtful), looks to me like you have a big exposure of deleting the selected records without being able to confirm that it is truly safe to do so. -
Calling OAM WLST Commands from java class
Hi all,
is there any idea how to call OAM related WLST commands from java class ?.
what are the required jar files ?
thanksHi,
As per my understanding in OAM you will have only two major .py file startscript.py and stopscript.py file which will start nodemanger connect and start Admin and managed server similarly in stop it will stop managed server Admin server and then last nodemanager.
these all done through wlst command using nmConnect(), nmStart (), nmKill() and shutdown etc.
What exactly you are looking to get from java code.
Regards,
kal -
Problem in Execution of DOS Commands with JAVA.
I am trying to execute DOS Commands and FTP commands using Java Programming Language and Trying to get the output for further processing.Actually I want the exact output what DOS and FTP give after execution of a their corresponding commands.
Process p = new Process("dir");
InputStream is = p.getInputStream(); -
Perform Windows _lopen command in Java
Hi all,
I would need to know if there is a possibilty to call the Windows Kernel Function "_lopen" in Java. Background is that I need to exclusively lock a File in a Win2K environment, so that another process can not access it.
The other process uses the _lopen command so it would be the correct way to use the same method (or it's Java representation) on my side.
So, is there a possibility to use this method from Java?!
Thanks for any help!!!
nocommHave a try with JNative.
--Marc (http://jnative.sf.net) -
Calling the system commands in Java
Hi All,
How to call the system commands in java other than using
exec() function.For eg, in my linux machine i have used p.exec("exit") to exit from a cshell to the prompt but it is not working.Is there any other solution for this one. Pls. do provide a solution for this.It is quite Urgent.
Thanks,
m.ananthuWhy not SEARCH THE F*ING FORUMS!! This has been answered SO MANY TIMES
-
I would like to know how to call cl command in java to delete a file in my server. thanks
Use the java.lang.Runtime interface. The exec() method allows you to execute commands from the command shell:
String cmd = new String[2];
cmd[0] = "cl";
cmd[1] = fileToDelete;
Runtime rt = Runtime.getRuntime();
rt.exec(cmd); -
Executing a dos command from java in windows nt
i need to execute the
" net send"
command from the command line in windows nt, from within my java program... is there any way that i can execute cmommands in the dos command shell? or rather, does anybody know a way i can send a message ( in windows ) from java, from one computer to another over the lan?? I cannot have a java programming running on all the other computers, so i cannot make my program serve, it must just send the messges using a lan command....
(the net send command just sends a message in the form of a pop up box on the receiver's screeen)
thanks a bunch guys!!!
Thanks a bunch guys!!!!you can do that with exec() in Runtime.
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command here);but before you do that you need to read this:
http://www.javaworld.com/jw-12-2000/jw-1229-traps.html
hth
partha -
How to call gnuplot command from java
Hi there,
In our course, we are required to develop an GUI for gnuplot. In case you don't know about gnuplot, it's a plotting program and has lots of command. We want to use java and swing, but now we don't know how to call gnuplot command from java, or how to execute a shell command(script) from java.
By the way, since we need read in files with several columns of data and allow user to select a column, we want to use JTable. Is that reasonable?
Thanks a lot for any suggestions!
JackHi, there:
Will using JTable add much overhead? I may have to use several JTables and switch among them. I can add scroll bar to or edit JTables, right?
BTW, do you have experience about gnuplot? Can I find the command tree of gnuplot somewhere? Or do you know a better place to post question about gnuplot? unix/linux group, maybe.
Thanks,
Jack
P.S. Would you guys answer my question after I use up my duke dollars? :- ) -
Could not able to execute FTP commands in windows server machines 2012/ windows server 2008.
From windows server 2012 and windows server 2008, Opened port 20,21,22 in firewall bidirectionally. After Establishing connection by passing credentials 230 log in successful.
ftp commands executing getting as " 425 Use Port or PASV first" , "500 Illegal PORT command".
But I could able to do windows client machines like windows 7 and windows 8 with same environment
Note : Firewall ports are opened. have tested by making firewall down to avoid filters.
Pandiyan MuthuramanHi Pandiyan Muthuraman,
Did you mean even you disable or open the related port the FTP issue still exist? I found this errors most time occur when we use the ISA firewall and the FTP configured passive
mode, if you have ISA firewall please refer the following KB to fix this issue.
How to enable passive CERN FTP connections through ISA Server 2000, 2004, or 2006
http://support.microsoft.com/kb/300641
The have a specific form for the IIS question, if you have the further IIS related question you can ask in IIS forum.
IIS support forum
http://forums.iis.net/
Thanks for your understanding and support
We
are trying to better understand customer views on social support experience, so your participation in this
interview project would be greatly appreciated if you have time.
Thanks for helping make community forums a great place.
Maybe you are looking for
-
Diffrence in incomming order qty and billing qty in cube 0sd_c03 & 0sd_c01
Dear All. i have uploaded 2 cubes 0SD_C01 & 0SD_C01 from our R/3 data, SAP recommed for 0SD_C03 for sales analysis and their best practice is also based on 0SD_C03 but it is very strange the values of both the cubes are not the same when i run the r
-
IPhone not uploading photos to iCloud Photo Library. Why?
I have 2 iPhones 6Plus's both fully updated. I have enabled them both to use iCloud Photo Library. One has synced up nicely, the other has not pulled any photos down from the cloud and says that it has 2,373 items to upload. Any ideas what could b
-
How to connect to airport extreme
How do I connect to my airport extreme? I need to add a second router to extend the range.
-
Portege R700 - What is the "Optical Drive auto lock" feature?
On my R700 (Windows 7) I see an icon in the taskbar that shows whether my Optical Drive is powered ON or OFF. I can toggle this with Fn-TAB. If you context click the icon it offers you "Optical Drive auto lock" and an "Unlock time settings" - what do
-
Problem syncing iPhoto 6 pics to my iPod touch...it adds an extra folder
Not sure which product forum to post this on, but here I go. I'm ending up with way too many photos on my iPod. When I sync my iPod touch in iTunes it asks for the source of pictures so I select iPhoto. Then it asks which specific albums I want to sy