Java实现类似WINSCP访问远程Linux服务器,执行命令、上传文件、下载文件

pom.xml添加的依赖: <!-- https://mvnrepository.com/artifact/ch.ethz.ganymed/ganymed-ssh2 --> <dependency> <groupId>ch.ethz.ganymed</groupId> <artifactId>ganymed-ssh2</artifactId> <version>262</version> </dependency> 这里注意,不同版本的这玩意用法有差别。这里我使用的是262。 操作类代码如下: import ch.ethz.ssh2.*; import java.io.*; /** * @Author: 风萧古道的博客 windypath.com * @Date: 2019/11/29 15:14 */ public class SSHUtil { // uploadFile to Linux /** * 上传文件到Linux * * @param ip ip地址 * @param username 登录用户名 * @param password 密码 * @param remoteFilePath 目标文件所在完整目录 * @param file 本地文件File对象 * @return */ public static boolean uploadFile(String ip, String username, String password, String remoteFilePath, File file) { FileInputStream input = null; BufferedOutputStream boutput = null; Connection conn = null; try { conn = new Connection(ip); conn....

二月 20, 2020 · JohnathanLin

一个被废弃的项目——自动爬取信息然后发给我自己邮箱上

这是一个python项目。 使用到的技术包括爬虫和发邮件 代码如下: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2020/2/5 22:49 # @Author : Johnathan Lin import time import requests import random import json import re from bs4 import BeautifulSoup import smtplib from email.mime.text import MIMEText from email.header import Header from urllib.parse import urljoin from bs4.element import NavigableString # 第三方 SMTP 服务 mail_host = "smtp.163.com" # 设置服务器 mail_user = "你的邮箱" # 用户名 mail_pass = "你的密码" # 口令 # 发送人和接收人 sender = '你的邮箱' # 自己发给自己就可以了, receivers = ['你的邮箱'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱 # 爬虫请求头 headers = { 'User-Agent': 'Mozilla/5....

二月 9, 2020 · JohnathanLin

Python连接MongoDB和Oracle实战

Python连接MongoDB 安装 首先要安装pymongo,用pip装一下就好了。 工具类python文件 以下直接给出我写的mongodb操作类 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/12/23 14:02 # @Author : Johnathan Lin 林佳庆 """ 数据导入Mongo模块 """ import os import pymongo from utils.configReader import read_mongo_config # 设置编码 os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' def get_mongodb_collection(collection): """ 根据配置文件和数据库和表得到表(collection) :param database: 数据库 :param collection: 表 :return: 表的对象 """ mongo_config = read_mongo_config() client = pymongo.MongoClient(mongo_config['client']) db = client[mongo_config['database']] if mongo_config['auth'] == 'True' or mongo_config['auth'] == 'true': db....

二月 9, 2020 · JohnathanLin

MongoDB常用查询语句

增删改查部分 MongoDB单条件查询 db.xxx.find({'city.value':'深圳市'}) 文档部分json结构为: { ... "city": { "chinese": "城市", "value": "深圳市" } } 使用key.key的形式,得到对应的value。 MongoDB与查询 db.xxx.find({$and:[{'city.value':'深圳市'},{'status': 'finished'}]}) MongoDB的Group By和Having db.xxx.aggregate( { $match: { 'city.value':'马鞍山市' } }, { $group : { _id : "$service", num_tutorial : { $sum : 1 } } }, { $match:{ num_tutorial:{ $gt:1 } } } ) $group指定对哪个属性分组,用num_tutorial来判断数量是否满足某个条件。 $gt:greater than 删除文档 db.xxx.remove({'city.value':'伊犁哈萨克自治州'}) 删除重复数据 删除某个属性重复的数据,只保留第一条 db.xxx.aggregate( { $match:{ 'city.value':‘xxx’ } }, { $group : { _id : "$service", num_tutorial : { $sum : 1 }, dups:{ $addToSet:'$_id' } } }, { $match:{ num_tutorial:{ $gt:1 } } })....

二月 9, 2020 · JohnathanLin

vue和springboot项目部署到Linux服务器

写在前面的话 前后端分离的项目中,需要分别部署前端与后端项目。前端项目使用npm打包,将得到的dist文件夹下的内容上传到服务器后,用nginx的alias指向文件夹即可访问,而后端项目使用maven打包,需使用tomcat在后台启动,再通过nginx转发,供前端项目调用。 打包 前端的打包 前端项目使用的是vue-element-admin的基础版本:vue-admin-template 根据教程从github上下载后,在webstorm中运行成功。 原项目中只有前端,但可以完成简单的数据交互,根据使用手册介绍,该项目使用了mockjs模拟数据。 而我们需要做前后端交互,故不使用mockjs。 修改为访问后端的路径 方法很简单,在根目录下的.env.development文件下,将VUE_APP_BASE_API改为你的本地后端地址。 .env.development VUE_APP_BASE_API = 'http://localhost:8080' 在根目录下的.env.production文件下,将VUE_APP_BASE_API改为你的云服务器的后端地址。 .env.production # just a flag ENV = 'production' # base api VUE_APP_BASE_API = 'http://???????/springbootdemo' 这里可能会有一些小bug,主要是要与服务器的路径对应起来。 根据该项目package.json内所设置的,使用npm run build:prod打包,生成dist文件夹 最后得到dist文件夹。 后端的打包 编写接口 首先,编写Controller,写一些接口。 package com.windypath.demo.controller; import com.windypath.demo.response.ResponseData; import com.windypath.demo.response.ResponseDataUtil; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RequestMapping("/") @RestController public class MainController { @RequestMapping("/hello") public ResponseData hello() { return ResponseDataUtil.buildSuccess("hello!"); } @RequestMapping("/") public ResponseData root() { return ResponseDataUtil.buildSuccess("root!"); } } 此处使用的ResponseData来自于https://blog....

一月 27, 2020 · JohnathanLin