ftp脚本如下
#!/bin/bash
ftp -v -n 192.168.1.31 << EOF
user app xj
binary
hash
cd /itfapp/reckfile/
lcd /home/Tmp
prompt
mput *
bye
EOF
我将这个脚本的内容放到根下,直接运行没有问题,但是使用java调用却无法上传,java代码如下
Process process = Runtime.getRuntime().exec(new String[] {
"sh", "/ftpfile"});
ftpfile中的内容就是上面那个脚本,运行后的输出如下:
调用ftpfile返回的结果是:Not connected.
调用ftpfile返回的结果是:Not connected.
调用ftpfile返回的结果是:Hash mark printing on (1024 bytes/hash mark).
调用ftpfile返回的结果是:Not connected.
调用ftpfile返回的结果是:Local directory now /home/Tmp
调用ftpfile返回的结果是:Interactive mode off.
调用ftpfile返回的结果是:Not connected.
不存在网络问题,前面已经说明直接运行ftpfile是可以上传的,请指教!我分不多,希望大家不要嫌弃!
第1个回答 2009-10-29
不要用sh来运行,用bash。sh 应该不支持here doc。
Process process = Runtime.getRuntime().exec(new String[] {
"sh", "/ftpfile"});
==>
Process process = Runtime.getRuntime().exec(new String[] {
"bash", "/ftpfile"});
Process process = Runtime.getRuntime().exec(new String[] {
"sh", "/ftpfile"});
==>
Process process = Runtime.getRuntime().exec(new String[] {
"bash", "/ftpfile"});