.net c#自动将新创建的文件上传到SFTP服务器

Automatically upload newly created files to an SFTP server
2020-11-21
  •  译文(汉语)
  •  原文(英语)

一个ASP.NET应用程序(在Windows服务器/ IIS 7上运行)必须将当前用户上传的大文件传输到外部SFTP服务器.由于文件大小,其想法是异步执行此操作.

这个想法是ASP.NET应用程序将上载的文件存储在Windows服务器的本地目录上.当前用户可以继续他的工作.Windows服务或Quartz作业(其他工具(*)/想法?)现在负责将文件传输到外部SFTP服务器.

(*)是否有现有的工具可以侦听Windows目录的更改,然后在SFTP服务器上移动文件(包括处理通信错误/重试)?

如果没有现有的解决方案,您是否有类似的要求?我们要考虑什么?由于与SFTP服务器的连接不是很稳定,因此我们需要具有自动重试功能的优化错误处理.

解决过程1

要监视.NET本地目录中的更改,请使用FileSystemWatcher.


如果你正在寻找一个开箱即用解决方案,使用keepuptodate命令WinSCP赋予脚本.

WinSCP脚本的一个简单示例(例如watch.txt):

open sftp://username:password@host/
keepuptodate c:\local_folder_to_watch /remote_folder
exit

像这样运行脚本:

winscp.com /script=watch.txt

尽管仅当上传的文件保留在远程文件夹中时,这才有效.

(我是WinSCP的作者)

速聊1:
感谢您的宝贵意见!

An ASP.NET application (running on Windows server/IIS 7) has to transfer big size files uploaded by current user to an external SFTP server. Due to the file size the idea is to do this asynchronously.

The idea is that the ASP.NET application stores the uploaded file on a local directory of the Windows server. The current user can continue his work. A Windows service or a Quartz job (other tools(*)/ideas?) is now responsible to transfer the file to the external SFTP server.

(*) Are there existing tools that listen on changes of a Windows directory and then move the files on a SFTP server (incl. handling communication errors/retries)?

If there is no existing solution, do you have had similar requirements? What do we have to consider? Because the connection to the SFTP server is not very stable we need an optimized error handling with auto retry functionality.

Solutions1

To watch for changes in a local directory in .NET, use the FileSystemWatcher class.


If you are looking for an out of the box solution, use the keepuptodate command in WinSCP scripting.

A simple example of WinSCP script (e.g. watch.txt):

open sftp://username:password@host/
keepuptodate c:\local_folder_to_watch /remote_folder
exit

Run the script like:

winscp.com /script=watch.txt

Though this works only, if the uploaded files are preserved in the remote folder.

(I'm the author of WinSCP)

Talk1:
Thanks for your great input!
转载于:https://stackoverflow.com/questions/28361601/automatically-upload-newly-created-files-to-an-sftp-server

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入