Ben java için yeni ve çeşitli günlük SFTP sitelerinden birden fazla dosya çekecek bir komut dosyası yazmaya çalışıyorum.Java kullanarak SFTP ile birden fazla dosya indirme
Aşağıda 1 koddan 1 dosya alacağım kod çalışıyor, ancak kodumu nasıl değiştireceğimi bulmaya çalışıyorum, böylece birden fazla dosya indirecek. Örneğin, uzak dizindeki tüm dosyalar ya da yalnızca belirli harfleri içeren belirli dosyalar
Bu konuda bana tavsiyede bulunabilir misiniz?
kod: -
package package1;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
public class SFTPpullsshkeys {
public SFTPpullsshkeys() {
}
public static void main(String[] args) {
String SFTPHOST = "IP";
int SFTPPORT = 22;
String SFTPUSER = "Username";
String passphrase = "passphrase";
String SFTPWORKINGDIR = "remote directory";
String prikeyfile = "C:\\Open SSH Key.ppk";
Session session = null;
Channel channel = null;
ChannelSftp channelSftp = null;
try{
JSch jsch = new JSch();
jsch.addIdentity(prikeyfile, passphrase);
session = jsch.getSession(SFTPUSER,SFTPHOST,SFTPPORT);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
channel = session.openChannel("sftp");
channel.connect();
channelSftp = (ChannelSftp)channel;
channelSftp.cd(SFTPWORKINGDIR);
byte[] buffer = new byte[1024];
BufferedInputStream bis = new BufferedInputStream(channelSftp.get("file.csv"));
File newFile = new File("C:\\file.csv");
OutputStream os = new FileOutputStream(newFile);
BufferedOutputStream bos = new BufferedOutputStream(os);
int readCount;
while
((readCount = bis.read(buffer)) > 0) {
System.out.println("Writing files to disk: ");
bos.write(buffer, 0, readCount);
}
bis.close();
bos.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
}
Lütfen bu kodun sorunu nasıl çözdüğünü açıklayın. – ChrisF