当前位置: 首页 > news >正文

上海网站建设高端定制网络服务公司网站优化方案教程

上海网站建设高端定制网络服务公司,网站优化方案教程,建设银行境外汇款申请书网站,标志设计logo网站首先要知道服务器的用户名和密码。 注意#xff1a;一般情况#xff0c;如果不是强制要求#xff0c;尽量不要将文件上传到服务器 步骤#xff1a; 1.导入依赖 !--图片上传到服务器需要的依赖-- dependency groupIdcom.jcr…首先要知道服务器的用户名和密码。 注意一般情况如果不是强制要求尽量不要将文件上传到服务器 步骤 1.导入依赖 !--图片上传到服务器需要的依赖--         dependency             groupIdcom.jcraft/groupId             artifactIdjsch/artifactId             version0.1.54/version         /dependency 2.编写配置文件application.yml customize:     remoteServer:         sftp:           SFTP_httpBaseUrl: /images/ # 访问附件的地址添加 一个映射 如  /images/ -》 /server-images/           SFTP_httpPort: 80 # 公网访问的端口           SFTP_directory: /server-images/ #主机保存附件目录           SFTP_host: 192.168.1.10 #主机           SFTP_port: 22 #端口号           SFTP_username: root #用户名           SFTP_password: 123456 #密码 3.编写文件上传所需要的工具类 import com.jcraft.jsch.*; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; import java.time.LocalDate; import java.util.Properties; import java.util.UUID; /**  * 类描述  * 上传文件到服务器的 工具类  *  * ClassName SFTPUtil  * Author msi  * Date 2020/9/2 23:29  * Version 1.0  */ Component public class SFTPUtil {     /**      * 返回公网访问的地址前缀      */     Value(${customize.remoteServer.sftp.SFTP_httpBaseUrl})     protected String baseUrl;     /**      * 公网访问的端口      */     Value(${customize.remoteServer.sftp.SFTP_httpPort})     protected int port;     /**      * 主机保存的目录      */     Value(${customize.remoteServer.sftp.SFTP_directory})     protected String directory;     /**      * 主机的IP      */     Value(${customize.remoteServer.sftp.SFTP_host})     protected String host;     /**      * ssh端口      */     Value(${customize.remoteServer.sftp.SFTP_port})     protected int sshPort;     /**      * 用户名      */     Value(${customize.remoteServer.sftp.SFTP_username})     protected String username;     /**      * 密码      */     Value(${customize.remoteServer.sftp.SFTP_password})     protected String password;     /**      * 上传多文件到指定远程主机      * param files     文件数组      * return list       */     public ListString uploadMultipartFilesToServer(MultipartFile[] files) throws SftpException, JSchException, IOException {         ListString list new ArrayList();         ChannelSftp sftp null;         Session session null;         sftp this.connect(this.host, this.sshPort, this.username, this.password);         session sftp.getSession();         for (int i 0; i files.length; i) {             String originalFilename files[i].getOriginalFilename();             // 生成文件夹名 yyyy-mm             String relativePath new StringBuilder().append(LocalDate.now().getYear())                     .append(-).append(LocalDate.now().getMonthValue()).toString();             String uuid UUID.randomUUID().toString().replace(-, ).toLowerCase();             int lastIndex originalFilename.lastIndexOf(.);             String fileSuffix originalFilename.substring(lastIndex);             String filePrefix originalFilename.substring(0, lastIndex);             String fileName new StringBuilder().append(filePrefix).append(uuid).append(fileSuffix).toString();             // 文件上层目录             String directory this.directory relativePath;             // 创建文件夹             this.createDir(directory, sftp);             // 进入文件夹内             sftp.cd(directory);             // 创建文件             sftp.put(files[0].getInputStream(), fileName);             // 拼接返回格式             String s new StringBuilder(http://).append(this.host).append(:).append(this.port)                     .append(this.baseUrl).append(relativePath).append(/).append(fileName).toString();             list.add(s);         }         // 关掉连接         sftp.disconnect();         sftp.getSession().disconnect();         return list;     }     /**      * 建立连接      * param host  主机      * param port  端口      * param username  用户名      * param password  密码      * return      */     public ChannelSftp connect(String host, int port, String username,                                String password) {         ChannelSftp sftp null;         try {             JSch jsch new JSch();             jsch.getSession(username, host, port);             Session sshSession jsch.getSession(username, host, port);             sshSession.setPassword(password);             Properties sshConfig new Properties();             sshConfig.put(StrictHostKeyChecking, no);             sshSession.setConfig(sshConfig);             sshSession.connect();             Channel channel sshSession.openChannel(sftp);             channel.connect();             sftp (ChannelSftp) channel;         } catch (Exception e) {             e.printStackTrace();         }         return sftp;     }     /**      * 创建目录      *      */     public void createDir(String createpath, ChannelSftp sftp) {         try {             if (isDirExist(sftp, createpath)) {                 sftp.cd(createpath);             }             String pathArry[] createpath.split(/);             StringBuffer filePath new StringBuffer(/);             // 循环创建目录             for (String path : pathArry) {                 if (path.equals()) {                     continue;                 }                 filePath.append(path /);                 if (isDirExist(sftp, filePath.toString())) {                     sftp.cd(filePath.toString());                 } else {                     // 建立目录                     sftp.mkdir(filePath.toString());                     // 进入并设置为当前目录                     sftp.cd(filePath.toString());                 }             }             sftp.cd(createpath);         } catch (SftpException e) {             e.printStackTrace();         }     }     /**      * 判断目录是否存在      */     public boolean isDirExist(ChannelSftp sftp, String directory) {         boolean isDirExistFlag false;         try {             SftpATTRS sftpATTRS sftp.lstat(directory);             isDirExistFlag true;             return sftpATTRS.isDir();         } catch (Exception e) {             if (e.getMessage().toLowerCase().equals(no such file)) {                 isDirExistFlag false;             }         }         return isDirExistFlag;     } }   4.编写对应controller进行调试 Autowired     private UpdateFileUtil sftpUtil;     /**      * 上传文件到服务器      *      * param files 图片      * return      */     PostMapping(/file)     public ResultListString file(MultipartFile[] files) throws Exception {         ListString paths sftpUtil.uploadMultipartFilesToServer(files);         return Result.ofSuccess(paths);     }
http://www.hkea.cn/news/14505793/

相关文章:

  • 中山市住房建设局网站中国纪检监察报网站
  • 建立自己公司网站的方法企业网站打不开的原因
  • 网站建站报价如何做推广
  • 建设工程信息网站怎么做淘宝客网站和APP
  • 网站建设备案美容会所网站模板下载
  • mysol做的选课网站专业做网站建设公司有哪些
  • 新网站 蜘蛛手机网站解决方案
  • 网站建设管理汇报南充房产管理网
  • p2p网站建设制作做封面的网站
  • 只使用html做简单网站wordpress更换主题白屏
  • 网站建设 应该考虑什么wiki wordpress
  • 外贸自建站多少钱一个如何判断网站做没做404
  • 自适应型网站建设服务电话做网站微信群
  • 网站直接登陆wordpress快手推广网站
  • 上传网站怎么安装一个人做企业网站要多少天
  • 贵阳做网站方舟网络网站模块建设方案
  • 广告素材网站哪个比较好宁波seo外包推广渠道
  • 端口扫描站长工具自己做音乐网站
  • php网站开发示例做网站必须先买域名吗
  • 娄底市住房和城乡建设局官方网站全网营销与seo
  • 大型建设网站制作网站设计错误
  • 网站 目录访问wordpress 文件存储
  • 58网站怎么做浏览度才高龙岩做网站推广
  • 广西网站建设推广服务老年门户网站建设的意义
  • 外贸做的社交网站有哪些网站建设设计原则
  • 凡客做网站怎么样中国建设银行网站个人客户
  • 国家电网 两学一做 网站企业网站建设广州
  • 做设计用的常用网站wordpress 文件夹名称
  • 网站建设伍际网络搭建电商平台
  • 怎么做网站的广告做购物网站表结构分析