简体   繁体   English

使用ReBex将不同的文件上传到FTP服务器?

[英]Using ReBex to upload different files to FTP server?

I think im headed in the right direction, but would like anyones input. 我认为我朝着正确的方向前进,但希望任何人都可以投入。 I am working on a console app that is supposed to look for files in multiple folders, and then upload any files found to each corresponding folder on the FTP server (which is mirrored to match my local directory). 我正在使用一个控制台应用程序,该应用程序应在多个文件夹中查找文件,然后将找到的所有文件上载到FTP服务器上的每个对应文件夹(已镜像以匹配我的本地目录)。 Im new to using Rebex and FTP uploads in general. 我是刚开始使用Rebex和FTP上传的新手。 So far my code looks like this: 到目前为止,我的代码如下所示:

            //Connect to SFTP server 
            Sftp ftp = new Sftp();
            ftp.Connect(ftpServerURL);
            ftp.Login(ftpUserName, ftpPassword);

            //Upload local files to SFTP Server
            if (ftp.IsConnected == true)
            {
                ftp.PutFile(sourceFilePath, sftpTargetFolder);
            }

My question is: Will this code read through each folder in my local directory and upload them to the sftpTargetFolder? 我的问题是:此代码是否可以读取本地目录中的每个文件夹,并将其上传到sftpTargetFolder? (sourceFilePath and sftpTargetFolder are currently defined in App.Config). (sourceFilePath和sftpTargetFolder当前在App.Config中定义)。 Is this even the best method to do this? 这是最好的方法吗? How do I go about catching errors during the upload? 如何在上传过程中捕获错误? ANY input is appreciated greatly!!! 任何输入,不胜感激! Thank you. 谢谢。

I think I found the solution, it seems to work in testing. 我想我找到了解决方案,它似乎可以在测试中工作。 Take it if you will. 随便吃吧。

            //Upload local files to FTP server 

            ftp.Upload(sourceFilePath, "/", Rebex.IO.TraversalMode.Recursive, Rebex.IO.TransferMethod.Copy, Rebex.IO.ActionOnExistingFiles.OverwriteOlder);
            ftp.Disconnect();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM