日期:2014-05-20  浏览次数:20870 次

java调用linux命令(通过ftp连接服务器并给上传的文件赋权限)
赋权命令:chmod 777 filename
服务器:linux1、linux2。

java程序在linux1上,通过ftp方式将文件上传到linux2上,如何上传后的文件执行chmod赋权语句?

网上搜索到的解决方式:
  1、 Runtime.getRuntime().exec("chmod 777 "+filename); ---执行后没有任何反应。
  2、调用FtpClient类中sendServer("chmod 777 "+filename+ " ")--执行后仍是没有任何反应。

在线等~

------解决方案--------------------
第一种方式肯定是不行的。java程序在linux1上运行命令改变linux2上的文件属性肯定是没戏。
第二种我没用过FtpClient,chmod命令本身是可以用FTP改变权限的。
------解决方案--------------------
FTP.sendCommand是The FTPCommand constant corresponding to the FTP command to send.
你要使用chmod,必须服务器能支持"site chmod"命令和使用FTP.sendSiteCommand

------解决方案--------------------
把ftpClient.sendCommand("chmod 644 " + filename); 换成ftpClient.sendCommand("chmod", 644 " + filename); 怎样?毕竟chmod是command,args是644+filename。