首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java DataReading谷歌云平台

Java DataReading谷歌云平台
EN

Stack Overflow用户
提问于 2017-08-03 09:05:34
回答 1查看 136关注 0票数 2

我有一个问题,我想使用java从Google平台的debian服务器上传数据(openoffice ),并将其保存在我的数据库中,但我做不到,因为我需要在我的java代码中添加ssh键。

如何将java连接到Google平台和debian实例?我不知道该怎么做。

我有:

  • Windows 10上的Java 7。
  • Debian服务器java 7
  • Google平台,带有assh键。

我的想法是: calc→java→ssh?→google平台→实例→java→数据库。

我使用了一个maven存储库JSch:

代码语言:javascript
复制
    public static void main(String[] args) {

        /*Below we have declared and defined the SFTP HOST, PORT, USER 
                   and Local private key from where you will make connection */
        String SFTPHOST = "ip";
        int    SFTPPORT = 22;
        String SFTPUSER = "user";
        // this file can be id_rsa or id_dsa based on which algorithm is used to create the key
        String privateKey = "file"; 
        String SFTPWORKINGDIR = "folder";

        JSch jSch = new JSch();
        Session     session     = null;
        Channel     channel     = null;
        ChannelSftp channelSftp = null;
        try {
            jSch.addIdentity(privateKey);
            System.out.println("Private Key Added.");
            session = jSch.getSession(SFTPUSER,SFTPHOST,SFTPPORT);
            System.out.println("session created.");

            java.util.Properties config = new java.util.Properties();
            config.put("StrictHostKeyChecking", "no");
            session.setConfig(config);
            session.connect();
            channel = session.openChannel("sftp");
            channel.connect();
            System.out.println("shell channel connected....");
            channelSftp = (ChannelSftp)channel;
            channelSftp.cd(SFTPWORKINGDIR);
            System.out.println("Changed the directory...");
        } catch (JSchException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SftpException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally{
            if(channelSftp!=null){
                channelSftp.disconnect();
                channelSftp.exit();
            }
            if(channel!=null) channel.disconnect();

            if(session!=null) session.disconnect();
        }
    }

}
EN

回答 1

Stack Overflow用户

发布于 2019-10-17 10:09:26

如果我已经清楚地理解了您的场景,我认为您应该将数据发送到Google云存储桶:看这儿

另外,看看gcp中的服务帐户和凭据,在prem :)上使用它们真的很容易。)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45479647

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档