Added auto-updater, started to transfer Skript over, did the feather and freeze.
This commit is contained in:
18
Uploader/build.gradle.kts
Normal file
18
Uploader/build.gradle.kts
Normal file
@@ -0,0 +1,18 @@
|
||||
plugins {
|
||||
id("java")
|
||||
}
|
||||
|
||||
group = "me.trouper"
|
||||
version = "1.0.0"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.github.mwiede:jsch:2.27.0")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
89
Uploader/src/main/java/me/trouper/uploader/Uploader.java
Normal file
89
Uploader/src/main/java/me/trouper/uploader/Uploader.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package me.trouper.uploader;
|
||||
|
||||
import com.jcraft.jsch.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
public class Uploader {
|
||||
public static void main(String[] args) {
|
||||
String sftpHost = "api.trouper.me";
|
||||
int sftpPort = 689;
|
||||
String sftpUser = "root";
|
||||
String privateKeyPath = "/home/wolf/.ssh/deepfield_id_ed25519";
|
||||
String localFile = "/run/media/wolf/1TB drive/IJ/IdeaProjects/CloneDupeCore/build/libs/CloneDupeCore-1.0.0-all.jar";
|
||||
String remoteDir = "/home/cdn/files/plugins/CloneDupe/";
|
||||
|
||||
Session session = null;
|
||||
ChannelSftp channelSftp = null;
|
||||
|
||||
try {
|
||||
JSch jsch = new JSch();
|
||||
jsch.addIdentity(privateKeyPath);
|
||||
|
||||
session = jsch.getSession(sftpUser, sftpHost, sftpPort);
|
||||
session.setConfig("StrictHostKeyChecking", "no");
|
||||
session.connect();
|
||||
|
||||
Channel channel = session.openChannel("sftp");
|
||||
channel.connect();
|
||||
channelSftp = (ChannelSftp) channel;
|
||||
|
||||
File file = new File(localFile);
|
||||
channelSftp.cd(remoteDir);
|
||||
|
||||
System.out.println("Uploading: " + file.getName());
|
||||
channelSftp.put(
|
||||
new FileInputStream(file),
|
||||
file.getName(),
|
||||
new ProgressMonitor(file.length()),
|
||||
ChannelSftp.OVERWRITE
|
||||
);
|
||||
|
||||
System.out.println("\nUpload successful!");
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
if (channelSftp != null) channelSftp.exit();
|
||||
if (session != null) session.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private static class ProgressMonitor implements SftpProgressMonitor {
|
||||
private final long totalSize;
|
||||
private long uploaded = 0;
|
||||
private int lastPercent = -1;
|
||||
|
||||
public ProgressMonitor(long totalSize) {
|
||||
this.totalSize = totalSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(int op, String src, String dest, long max) {
|
||||
System.out.println("Starting upload...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean count(long count) {
|
||||
uploaded += count;
|
||||
int percent = (int)((uploaded * 100) / totalSize);
|
||||
if (percent != lastPercent) {
|
||||
StringBuilder bar = new StringBuilder("\r[");
|
||||
int progress = percent / 2;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
bar.append(i < progress ? "=" : " ");
|
||||
}
|
||||
bar.append("] ").append(percent).append("%");
|
||||
System.out.print(bar);
|
||||
lastPercent = percent;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
System.out.println("\nUpload complete.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user