0
我想開發一個Java程序,將文件從SFTP服務器下載到遠程服務器。該遠程服務器沒有任何共享路徑。我必須直接從sftp下載並粘貼到遠程Windows服務器驅動程序(D :)中。將SFTP文件直接下載到遠程服務器文件夾(不是共享路徑)
代碼:
int ftpPort = 22;
JSch jsch = new JSch ();
Session session = null;
Channel channel = null;
ChannelSftp c = null;
try {
session = jsch.getSession(username, hostname, ftpPort);
logger.info("*** FTP Session created. ***");
session.setPassword(password);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
logger.info("*** Session connected. ***");
//Open the SFTP channel
logger.info("*** Opening FTP Channel. ***");
channel = session.openChannel("sftp");
channel.connect();
c = (ChannelSftp) channel;
//Change to the remote directory
logger.info("*** Changing to FTP remote dir: " + remoteDirectory + " ***");
c.cd(remoteDirectory);
//Send the file we generated
try {
logger.info("*** Storing file:'" + filename + "' to local directory: '"+localDirectory+"'");
我使用Jsch和ChannelSftp連接到SFTP服務器。
截至目前,上述代碼將代碼下載到本地路徑和共享路徑。
任何建議將文件下載到不具有任何共享路徑的遠程服務器(Windows)。
謝謝。