如何使用VLC在SSH服务器上(使用sftp或smth其他)监视文件(正在修改文件)?

西尔

我正在使用ssh服务器录制视频,并且希望在录制过程中(在使用Windows 7或8的PC上)观看视频。我当然可以在看完文件后传输文件,但是我想在录制过程中看文件,这可以持续2个小时。

我不想使用VLC服务器,因为它可以对视频进行编码,而我的SSH服务器位于Odroid C1上(我认为它的功能不够强大),我会降低一些质量。

我在这里看到了一些想法VLC:是否可以通过SSH流式传输?但这还不够。

我在这里考虑了2个角度:

  • 寻找一种“无限期”下载文件的方法:这意味着只要文件变大,下载就会继续。但是我不知道这是否可行,我尝试过WinSCP,但即使文件不断更新,下载也结束了。
  • 在VLC“ sftp:///”中以类似方式流式传输文件,但是我不知道如何配置与VLC的连接(我的SSH连接不在端口22上,并且我使用公用/专用密钥)。

有人有什么想法吗?

西尔

由于我所有尝试直接通过带有“ sftp://”链接的VLC进行流式传输的尝试均告失败,因此我设法编写了一个小型Java程序,该程序可以通过下载文件并始终检查远程文件的大小来实现所需的功能已更改为恢复下载(如果需要)。

这里的关键是那段代码:

    sftpChannel.get(remotePath, outstream, monitor, ChannelSftp.OVERWRITE, 0);
    long localSize;
    Thread.sleep(1000);
    while(sftpChannel.lstat(remotePath).getSize() > (localSize = new File(localPath).length())){
        sftpChannel.get(remotePath, outstream, monitor, ChannelSftp.RESUME, localSize);
        Thread.sleep(timeToWaitBeforeUpdatingFile);

    }
    System.out.println("The download is finished.");

如果有人感兴趣,我还将发布该程序的整个代码:

package streamer;

import java.io.Console;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.Vector;

import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
import com.jcraft.jsch.SftpProgressMonitor;

public class Streamer {
    public static void main(String[] args) throws InterruptedException, IOException {
        JSch jsch = new JSch();

        if(args.length != 7){
            System.out.println("Incorrect parameters:");
            System.out.println("Streamer user host port privateKeyPath remotePath localPath vlcPath");
            System.exit(-1);
        }

        String user = args[0];
        String host = args[1];
        int port = -1;
        try {
            port = Integer.parseInt(args[2]);
        } catch (NumberFormatException e3) {
            System.out.println("Port must be an integer");
            System.exit(-1);
        }
        String privateKeyPath = args[3];

        String remotePath = args[4];
        String localPath = args[5];
        String vlcPath = args[6];

        int timeToWaitBeforeUpdatingFile = 5000;
        String password = "";

        Console console = System.console();
        if (console == null) {
            System.out.println("Couldn't get Console instance");
            //password = "";
            System.exit(-1);
        }else{
            char passwordArray[] = console.readPassword("Enter your password: ");
            password = new String(passwordArray);
            Arrays.fill(passwordArray, ' ');
        }

        try {
            jsch.addIdentity(privateKeyPath, password);
        } catch (JSchException e) {
            System.out.println(e.getMessage());
            System.out.println("Invalid private key file");
            System.exit(-1);
        }

        Session session;
        try {
            session = jsch.getSession(user, host, port);
            java.util.Properties config = new java.util.Properties();
            config.put("StrictHostKeyChecking", "no");
            session.setConfig(config);

            System.out.println("Establishing connection...");
            session.connect();
            System.out.println("Connection established.");
            System.out.println("Creating SFTP Channel...");
            ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
            sftpChannel.connect();
            System.out.println("SFTP Channel created.");

            try {
                @SuppressWarnings("unchecked")
                Vector<ChannelSftp.LsEntry> recordings = sftpChannel.ls(remotePath + "*.mpeg");
                if(recordings.isEmpty()){
                    System.out.println("There are no recordings to watch.");
                    System.exit(0);
                }
                int choice = 1;
                System.out.println("Chose the recording to watch:");
                for (ChannelSftp.LsEntry e : recordings){
                    System.out.println("[" + choice++ + "] " + e.getFilename());
                }
                Scanner sc = new Scanner(System.in);
                try {
                    String fileName = recordings.get(sc.nextInt() - 1).getFilename();
                    remotePath += fileName;
                    localPath += fileName;
                } catch (InputMismatchException e) {
                    System.out.println("Incorrect choice");
                    System.exit(-1);
                }
                System.out.println("You chose : " + remotePath);
                sc.close();
            } catch (SftpException e2) {
                System.out.println("Error during 'ls': the remote path might be wrong:");
                System.out.println(e2.getMessage());
                System.exit(-1);
            }

            OutputStream outstream = null;
            try {
                outstream = new FileOutputStream(new File(localPath));
            } catch (FileNotFoundException e) {
                System.out.println("The creation of the file" + localPath + " failed. Local path is incorrect or writing permission is denied.");
                System.exit(-1);
            }

            try {
                SftpProgressMonitor monitor = null;
                System.out.println("The download has started.");
                System.out.println("Opening the file in VLC...");
                try {
                    Runtime.getRuntime().exec(vlcPath + " " + localPath);
                } catch (Exception ex) {
                    System.out.println("The file couldn't be opened in VLC");
                    System.out.println("Check your VLC path.");
                    System.out.println(ex);
                }
                sftpChannel.get(remotePath, outstream, monitor, ChannelSftp.OVERWRITE, 0);
                long localSize;
                Thread.sleep(1000);
                while(sftpChannel.lstat(remotePath).getSize() > (localSize = new File(localPath).length())){
                    sftpChannel.get(remotePath, outstream, monitor, ChannelSftp.RESUME, localSize);
                    Thread.sleep(timeToWaitBeforeUpdatingFile);

                }
                System.out.println("The download is finished.");
                outstream.close();
                System.exit(0);
            } catch (SftpException e1) {
                System.out.println("Error during the download:");
                System.out.println(e1.getMessage());
                System.exit(-1);
            }
        } catch (JSchException e) {
            System.out.println("Connection has failed (check the user, host, port...)");
            System.exit(-1);
        }
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何使用连接到文件中其他位置下的服务器进行多跳 ssh

来自分类Dev

如何使用Spring从SFTP服务器获取zip文件

来自分类Dev

使用AJAX从其他远程服务器获取文件?

来自分类Dev

如何在 Ubuntu 服务器上使用 SFTP 删除获取的文件?

来自分类Dev

使用.htaccess重写规则重定向到服务器上的其他文件夹

来自分类Dev

如果不使用其他远程服务器,则无法SSH / SFTP到远程服务器

来自分类Dev

检查其他服务器上的文件

来自分类Dev

恢复文件系统其他服务器时如何不覆盖ssh配置?

来自分类Dev

使用Node.js和SSH2从SFTP服务器读取文件

来自分类Dev

使用SSH.NET从SFTP服务器下载一个特定文件

来自分类Dev

在PowerShell中使用WinSCP .NET程序集监视FTP服务器上的上传文件

来自分类Dev

如何使用ssh从一台服务器上的文件复制文本并追加到另一台服务器上的文件?

来自分类Dev

如何使用 ftplib 写入远程服务器上的文件

来自分类Dev

如何列出位于其他服务器上的文件夹权限

来自分类Dev

不使用 JSch 从 SFTP 服务器下载文件

来自分类Dev

使用批处理文件和PuTTY在远程服务器上执行sftp命令

来自分类Dev

使用批处理文件和PuTTY在远程服务器上执行sftp命令

来自分类Dev

如何使用reveal.js本地服务器查看其他文件夹中的HTML

来自分类Dev

在旧服务器上使用新服务器上的SSH中的Bash脚本自动传输文件

来自分类Dev

如何使用SharpSSH将文件移动到SFTP服务器

来自分类Dev

如何使用Paramiko从SFTP服务器仅下载最新文件?

来自分类Dev

如何使用Powershell将文件从SFTP复制到本地主机(Windows服务器)

来自分类Dev

当文件位于其他服务器上时,使用ASP.Net MVC在浏览器中强制下载文件,而无需先在我的服务器上下载文件

来自分类Dev

如何强制wget在不修改系统文件的情况下使用代理服务器?

来自分类Dev

如何强制wget在不修改系统文件的情况下使用代理服务器?

来自分类Dev

文件类型是.NET?服务器上的其他站点是“文件夹”

来自分类Dev

文件位于其他服务器上时,.NET下载一个Zip文件

来自分类Dev

使用1个站点的mp4文件到使用htaccess托管在同一服务器上的其他站点

来自分类Dev

使用ssh.net在ubuntu服务器上写入文件末尾

Related 相关文章

  1. 1

    如何使用连接到文件中其他位置下的服务器进行多跳 ssh

  2. 2

    如何使用Spring从SFTP服务器获取zip文件

  3. 3

    使用AJAX从其他远程服务器获取文件?

  4. 4

    如何在 Ubuntu 服务器上使用 SFTP 删除获取的文件?

  5. 5

    使用.htaccess重写规则重定向到服务器上的其他文件夹

  6. 6

    如果不使用其他远程服务器,则无法SSH / SFTP到远程服务器

  7. 7

    检查其他服务器上的文件

  8. 8

    恢复文件系统其他服务器时如何不覆盖ssh配置?

  9. 9

    使用Node.js和SSH2从SFTP服务器读取文件

  10. 10

    使用SSH.NET从SFTP服务器下载一个特定文件

  11. 11

    在PowerShell中使用WinSCP .NET程序集监视FTP服务器上的上传文件

  12. 12

    如何使用ssh从一台服务器上的文件复制文本并追加到另一台服务器上的文件?

  13. 13

    如何使用 ftplib 写入远程服务器上的文件

  14. 14

    如何列出位于其他服务器上的文件夹权限

  15. 15

    不使用 JSch 从 SFTP 服务器下载文件

  16. 16

    使用批处理文件和PuTTY在远程服务器上执行sftp命令

  17. 17

    使用批处理文件和PuTTY在远程服务器上执行sftp命令

  18. 18

    如何使用reveal.js本地服务器查看其他文件夹中的HTML

  19. 19

    在旧服务器上使用新服务器上的SSH中的Bash脚本自动传输文件

  20. 20

    如何使用SharpSSH将文件移动到SFTP服务器

  21. 21

    如何使用Paramiko从SFTP服务器仅下载最新文件?

  22. 22

    如何使用Powershell将文件从SFTP复制到本地主机(Windows服务器)

  23. 23

    当文件位于其他服务器上时,使用ASP.Net MVC在浏览器中强制下载文件,而无需先在我的服务器上下载文件

  24. 24

    如何强制wget在不修改系统文件的情况下使用代理服务器?

  25. 25

    如何强制wget在不修改系统文件的情况下使用代理服务器?

  26. 26

    文件类型是.NET?服务器上的其他站点是“文件夹”

  27. 27

    文件位于其他服务器上时,.NET下载一个Zip文件

  28. 28

    使用1个站点的mp4文件到使用htaccess托管在同一服务器上的其他站点

  29. 29

    使用ssh.net在ubuntu服务器上写入文件末尾

热门标签

归档