【问题标题】:Auto FTP from a Directory来自目录的自动 FTP
【发布时间】:2012-05-06 05:50:29
【问题描述】:

我想监视一个目录并将其中的所有文件通过 FTP 传输到 FTP 位置。有谁知道如何在 C# 中做到这一点?

谢谢

编辑:任何人都知道可以监控目录和 FTP 以及放置在其中的文件的好客户端吗?

【问题讨论】:

    标签: c# ftp


    【解决方案1】:

    System.IO.FileSystemWatcherSystem.Net.FtpWebRequest/FtpWebResponse 类的组合。

    我们需要更多信息才能更具体。

    【讨论】:

    • 1.监视任何新文件的特定目录(“FTP-IN”)。 2. 获取该文件并将其通过 FTP 传输到 Web 服务器。 3. 将文件从“FTP-IN”目录移动到另一个目录。 4. 回到#1。
    【解决方案2】:

    当与 FileSystemWatcher 结合使用时,此代码是一种将文件上传到服务器的快速而肮脏的方式。

    public static void Upload(string ftpServer, string directory, string file)
    {
        //ftp command will be sketchy without this
        Environment.CurrentDirectory = directory;  
    
        //create a batch file for the ftp command
        string commands = "\n\nput " + file + "\nquit\n";
        StreamWriter sw = new StreamWriter("f.cmd");
        sw.WriteLine(commands);
        sw.Close();
    
        //start the ftp command with the generated script file
        ProcessStartInfo psi = new ProcessStartInfo("ftp");
        psi.Arguments = "-s:f.cmd " + ftpServer;
    
        Process p = new Process();
        p.StartInfo = psi;
    
        p.Start();
        p.WaitForExit();
    
        File.Delete(file);
        File.Delete("f.cmd");
    }
    

    【讨论】:

      猜你喜欢
      • 2012-02-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多