程序包 org.anyline.net

类 SFTPUtil

java.lang.Object
org.anyline.net.SFTPUtil

public class SFTPUtil extends Object
  • 构造器详细资料

  • 方法详细资料

    • getInstance

      public static SFTPUtil getInstance(String host, String account, String password, int port)
    • getInstance

      public static SFTPUtil getInstance(String host, String account, String password)
    • download

      public void download(String remote, String local) throws Exception
      下载文件-sftp协议.
      参数:
      remote - 下载的文件
      local - 存在本地的路径
      抛出:
      Exception - 异常 异常
    • disconnect

      public boolean disconnect()
      断开连接
      返回:
      boolean
    • fileSize

      public int fileSize(String remoteDir)
    • deleteFile

      public void deleteFile(String path) throws com.jcraft.jsch.SftpException
      删除文件-sftp协议.
      参数:
      path - 要删除的文件
      抛出:
      com.jcraft.jsch.SftpException - 异常
    • deleteDir

      public void deleteDir(String path) throws com.jcraft.jsch.SftpException
      删除文件夹-sftp协议.如果文件夹有内容,则会抛出异常.
      参数:
      path - 文件夹路径
      抛出:
      com.jcraft.jsch.SftpException - SftpException
    • uploadFile

      public void uploadFile(String localFile, String remoteDir, String remoteFile) throws com.jcraft.jsch.SftpException
      上传文件-sftp协议.
      参数:
      localFile - 源文件
      remoteDir - 远程保存路径
      remoteFile - 远程保存文件名
      抛出:
      com.jcraft.jsch.SftpException - 异常
    • uploadFile

      public void uploadFile(File localFile, String remoteDir, String remoteFile) throws com.jcraft.jsch.SftpException
      抛出:
      com.jcraft.jsch.SftpException
    • uploadFile

      public boolean uploadFile(String localFile) throws com.jcraft.jsch.SftpException
      上传文件-sftp协议.
      参数:
      localFile - 源文件路径,/xxx/xx.yy 或 x:/xxx/xxx.yy
      返回:
      上传成功与否
      抛出:
      com.jcraft.jsch.SftpException - 异常
    • mkdir

      public boolean mkdir(String dir) throws com.jcraft.jsch.SftpException
      根据路径创建文件夹.
      参数:
      dir - 路径 必须是 /xxx/xxx/ 不能就单独一个/
      返回:
      boolean
      抛出:
      com.jcraft.jsch.SftpException - 异常
    • mkdirs

      public boolean mkdirs(String dir) throws com.jcraft.jsch.SftpException
      递归创建文件夹.
      参数:
      dir - 路径
      返回:
      是否创建成功
      抛出:
      com.jcraft.jsch.SftpException - 异常
    • dirExist

      public boolean dirExist(String dir)
      判断文件夹是否存在.
      参数:
      dir - 文件夹路径, /xxx/xxx/
      返回:
      是否存在
    • files

      public List<String> files(String dir)
    • fileExists

      public boolean fileExists(String dir, String file)
    • fileExists

      public boolean fileExists(String path)