java访问liunx服务器

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Dean_xin_lan/article/details/78667439
package com.lx.ssmall.utils;


import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;


import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.SCPClient;
import ch.ethz.ssh2.SFTPv3Client;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;


/**
 * SCPClient连接liunx并进行增删改查
 * 注意除去文件下载其他操作都需要liunx文件操作,切记别误删其他文件特别是etc文件
 * @author LuoXu
 *
 */
public class SCPUtil {
//liunx Ip
private static String hostname = "xx.xx.xx.xx";
//默认端口
private static int port = 22;
//登录名
private static String user = "******";
//密码
private static String password = "******";

public static void getLiunxService(){
Map<String,Object> map = new HashMap<String,Object>();
//建立连接
Connection con = new Connection(hostname);
try {
//连接
con.connect();
//连接账号密码
boolean b = con.authenticateWithPassword(user, password);
if(b){
File file = new File("本机下载地址");
    if(!file.exists()){
    //如果没有就创建文件
    file.mkdir();
    }
//建立SCP客户端
SCPClient scp = con.createSCPClient();
//下载
scp.get("liunx服务器上下载的文件地址", file.getPath());
//上传(注意该用户必须拥有liunx文件的操作权限否则不行)
scp.put("localFile", "remoteTargetDirectory");
//远程新建文件
SFTPv3Client sft = new SFTPv3Client(con);
//创建文件一般在linux下面的/home/"user(用户名)"/下面
sft.createFile("newRemoteFile");
//文件移动
sft.mv("oldPath", "newPath");
//文件删除
sft.rm("fileName");
//建立会话
Session session = null;
session = con.openSession();
session.execCommand("ls liunx某个文件夹地址");
//利用会话可以操作远程服务器
//显示执行命令后的信息
InputStream stdout = new StreamGobbler(session.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true) {
String line = br.readLine();
if (line == null) {
break;
    }
//此为遍历文件,文件夹的目录
    System.out.println(line);
}
//获得推出状态
System.out.println("ExitCode: " + session.getExitStatus());
session.close();
}else{
System.out.println("连接失败");
}
} catch (IOException e) {
e.printStackTrace();
}finally{
con.close();
}
}

public static void main(String [] args){
getLiunxService();
}
}
展开阅读全文

访问mysql的问题在liunx

07-27

<%rn String database_username="iccsb";rn String database_password="bio4348";rn String url="jdbc:mysql://localhost:3306/cyp";rn //数据库连接rn Class.forName("com.mysql.jdbc.Driver").newInstance(); rn Connection conn= DriverManager.getConnection(url,database_username,database_password);rn Statement stmt=conn.createStatement();rn%>rn我连接mysql的语句,我的连接语句有问题吗rnrnrn报的错误,在本地没有错误,可传到服务器上就有错误了rnrntype Exception report rnrnmessage rnrndescription The server encountered an internal error () that prevented it from fulfilling this request. rnrnexception rnrnorg.apache.jasper.JasperException: Access denied for user 'iccsb'@'127.0.0.1' (using password: YES) rnorg.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460) rnorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355) rnorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) rnorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) rnjavax.servlet.http.HttpServlet.service(HttpServlet.java:729) rnrnrnroot cause rnrnjavax.servlet.ServletException: Access denied for user 'iccsb'@'127.0.0.1' (using password: YES) rnorg.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841) rnorg.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774) rnorg.apache.jsp.login_jsp._jspService(login_jsp.java:121) rnorg.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) rnjavax.servlet.http.HttpServlet.service(HttpServlet.java:729) rnorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331) rnorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) rnorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) rnjavax.servlet.http.HttpServlet.service(HttpServlet.java:729) rnrnrnroot cause rnrnjava.sql.SQLException: Access denied for user 'iccsb'@'127.0.0.1' (using password: YES) rncom.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926) rncom.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:771) rncom.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3647) rncom.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1176) rncom.mysql.jdbc.Connection.createNewIO(Connection.java:2544) rncom.mysql.jdbc.Connection. (Connection.java:1474) rncom.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266) rnjava.sql.DriverManager.getConnection(DriverManager.java:512) rnjava.sql.DriverManager.getConnection(DriverManager.java:171) rnorg.apache.jsp.login_jsp._jspService(login_jsp.java:56) rnorg.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) rnjavax.servlet.http.HttpServlet.service(HttpServlet.java:729) rnorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331) rnorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) rnorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) rnjavax.servlet.http.HttpServlet.service(HttpServlet.java:729) rnrnrn 论坛

java 获取webservice 接口数据 在liunx 服务器下出错

12-04

ChinaStockWebServiceClient client = new ChinaStockWebServiceClient();rnChinaStockWebServiceSoap s = client.getChinaStockWebServiceSoap();rnSystem.out.println("通过类型获取图片byte数组="+"代号:"+stockCode+"图片类型:"+stockType);rn byte[] b = s.getStockImage_kByteByCode(stockCode,stockType);rn // s.getStockImage_kByteByCode 就报了异常啦 特别声明 windows下ok linux 下就不行了rn System.out.println("图片已成功获取");rn tryrn rn OutputStream os = new FileOutputStream(imagePath+File.separator+imageName);rn os.write(b);rn os.flush();rn os.close();rn catch(Exception ee)rn rn rnrnrnrn//////////////////////////////////////////////////////////////////////rnjava.lang.reflect.InvocationTargetExceptionrn at sun.reflect.GeneratedMethodAccessor247.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:585)rn at com.citgee.web.mvc.ControllerHandler.executeController(ControllerHandler.java:55)rn at com.citgee.web.mvc.RequestProcessor.executeController(RequestProcessor.java:146)rn at com.citgee.web.mvc.RequestProcessor.process(RequestProcessor.java:31)rn at com.citgee.web.mvc.DispatcherServlet.service(DispatcherServlet.java:24)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)rn at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:103)rn at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:167)rn at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:226)rn at com.caucho.server.hmux.HmuxRequest.handleRequest(HmuxRequest.java:424)rn at com.caucho.server.port.TcpConnection.run(TcpConnection.java:477)rn at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:591)rn at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:513)rn at java.lang.Thread.run(Thread.java:595)rnCaused by: org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Fault: java.lang.UnsupportedOperationExceptionrn at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:92)rn at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)rn at $Proxy15.getStockImage_kByteByCode(Unknown Source)rn at com.eduhome.blog.stock.webxml.ChinaStockWebServiceClient.getStockImage(ChinaStockWebServiceClient.java:94)rn at com.eduhome.blog.stock.StockProxy.valueOfStockImage(StockProxy.java:46)// 报错位置就是上面我发的那段代码, 字符串数据可以获取, 就是获取 股市k线图 返回byte[] 就错了rn at com.eduhome.blog.stock.StockController.getStockInfo(StockController.java:344)rn ... 16 morernCaused by: org.codehaus.xfire.fault.XFireFault: Fault: java.lang.UnsupportedOperationExceptionrn at org.codehaus.xfire.fault.XFireFault.createFault(XFireFault.java:89)rn at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:83)rn at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)rn at org.codehaus.xfire.client.Client.invoke(Client.java:336)rn at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)rn ... 21 morernCaused by: java.lang.UnsupportedOperationExceptionrn at com.caucho.xml.stream.NamespaceContextImpl.getNamespaceURI(NamespaceContextImpl.java:121)rn at org.codehaus.xfire.util.NamespaceHelper.getUniquePrefix(NamespaceHelper.java:154)rn at org.codehaus.xfire.service.binding.WrappedBinding.writeStartElement(WrappedBinding.java:105)rn at org.codehaus.xfire.service.binding.WrappedBinding.writeMessage(WrappedBinding.java:78)rn at org.codehaus.xfire.soap.SoapSerializer.writeMessage(SoapSerializer.java:80)rn at org.codehaus.xfire.transport.http.HttpChannel.writeWithoutAttachments(HttpChannel.java:56)rn at org.codehaus.xfire.transport.http.CommonsHttpMessageSender.getByteArrayRequestEntity(CommonsHttpMessageSender.java:422)rn at org.codehaus.xfire.transport.http.CommonsHttpMessageSender.send(CommonsHttpMessageSender.java:360)rn at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:123)rn at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)rn at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)rn at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)rn at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)rn ... 24 more 论坛

没有更多推荐了,返回首页