Aller au contenu | Aller au menu | Aller à la recherche


SFTP (SSH File Transfer Protocol)

SFTP (SSH File Transfer Protocol), n'est pas FTP exécuté sur SSH, mais plutôt un nouveau protocole conçu dès le départ par le groupe de travail IETF SECSH. Il est parfois confondu avec Simple File Transfer Protocol.

STFP est un protocole de communication fonctionnant au-dessus de SSH à ne pas confondre avec File Transfer Protocol over SSL, abrégé FTPS.

SFTP JAVA

Apache Commons VFS

Commons VFS provides a single API for accessing various different file systems. It presents a uniform view of the files from various different sources, such as the files on local disk, on an HTTP server, or inside a Zip archive.

  • Support for numerous file system types
    • SFTP Provides access to the files on an SFTP server (that is, an SSH or SCP server).
      • You will also need to download the jars used by Commons VFS. Required for SFTP : JSch

Chilkat

Chilkat Class Libraries for Java, commercially licensed components include: SFTP

Jaramiko

Jaramiko is a port of paramiko for java: a pure-java implementation of the SSH version 2 protocol,

JSch

JSch is a pure Java implementation of SSH2.

Examples/SftpFileCopyExample

jsch javadoc, jsch don't provide documentation (in source, or html), alternativly, there is a documented version of JSch with downloadable or onlive Jsch Javadoc

package com.placeoweb;
 
import java.util.Properties;
 
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
 
public class Sftp {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int port = 22;
		String username = "root";
		String host = "my.host.com";
		String pass = "myPassword";
		String khfile = "/home/testuser/.ssh/known_hosts";
		String identityfile = "/home/testuser/.ssh/id_rsa";
 
		JSch jsch = null;
		Session session = null;
		Channel channel = null;
		ChannelSftp c = null;
		try {
			jsch = new JSch();
			session = jsch.getSession(username, host, port);
			session.setPassword(pass);
			//			jsch.setKnownHosts(khfile);
			//			jsch.addIdentity(identityfile);
 
			//			http://stackoverflow.com/questions/4852016/jcraft-jsch-without-interactive-popup-windows
			Properties config = new java.util.Properties();
			config.put("StrictHostKeyChecking", "no");
			session.setConfig(config);
 
			session.connect();
 
			channel = session.openChannel("sftp");
			channel.connect();
			c = (ChannelSftp) channel;
 
			System.out.println("is Connected !");
 
			System.out.println("Starting File Upload:");
			String fsrc = "C:\\src.txt", fdest = "/tmp/cde.txt";
			c.put(fsrc, fdest);
 
			c.get(fdest, "C:\\src.copy.by.upload.and.download.txt");			
 
		} catch (Exception e) { 	
			e.printStackTrace();
 
			/* 
Without setKnownHosts et addIdentity
=> com.jcraft.jsch.JSchException: UnknownHostKey: my.host.com. RSA key fingerprint is 42:28:d5:d4:73:d7:74:3d:62:f5:74:70:16:75:d3:a6
 
Without setKnownHosts et addIdentity + config "StrictHostKeyChecking", "no"
=> OK
			 */
		}
 
		c.disconnect();
		session.disconnect();
	}
 
}

Sshj

Sshj - SSHv2 library for Java

SSHTools

SSHTools is a suite of Java SSH applications providing a Java SSH API, SSH Terminal, SSH secured VNC client, SFTP client and SSH Daemon.

Zehon File Transfer Pack

Zehon File Transfer Pack for Java.

SFTP – should be only used for SFTP, the SSH file transfer protocol. However, people often shorten Secure FTP into SFTP - this is not correct, because the S in SFTP does not stand for Secure, but for SSH.

Ressources sur SFTP en JAVA

SFTP PHP

Ressources

Ajouter un commentaire

Le code HTML est affiché comme du texte et les adresses web sont automatiquement transformées.

Fil des commentaires de ce billet