简体   繁体   English

如何正确地将动态文件写入FTP服务器?

[英]How to correctly write dynamic files to an FTP server?

I'm using C# and i have written a locally installed application that dynamically generates files which need to be on an FTP server. 我正在使用C#,并且编写了本地安装的应用程序,该应用程序动态生成需要在FTP服务器上的文件。

Do i generate them to disk then upload them to the FTP server? 我是否将它们生成到磁盘然后上传到FTP服务器? or is there a way to open a stream to an FTP server and write the files directly? 或有没有办法打开到FTP服务器的流并直接写入文件?

Check the code sample I gave in this answer, doesn't rely on writing to files. 检查我在此答案中给出的代码示例,它不依赖于写入文件。 It's not SQL specific and was just a suggestion on how to use SQL CLR integration assemblies to upload output from sql queries to an FTP server. 它不是特定于SQL的,只是关于如何使用SQL CLR集成程序集将sql查询的输出上载到FTP服务器的建议。 The for loop in the method is just to demonstrate writing to the FTP stream. 该方法中的for循环仅用于演示如何写入FTP流。 You should be able to rework to you needs: 您应该能够根据需要进行返工:

How to write stored procedure output directly to a file on an FTP without using local or temp files? 如何在不使用本地或临时文件的情况下将存储过程输出直接写入FTP上的文件?

更好的方法是将文件保存在本地,然后再上传,因为上传过程可能会出现问题。

You should follow the class: 您应该遵循以下课程:

System.Net.FtpWebRequest

You will see that its arguments are streams and you can send data to them from any source. 您将看到它的参数是流,并且可以从任何源向它们发送数据。

When seaching for .Net capabilities you should be aware of the object browser for visual studio acessible in: 搜寻.Net功能时,您应该注意Visual Studio的对象浏览器,可通过以下方式访问:

View > other windows > object browser 查看>其他窗口>对象浏览器

Is supplies a search over all known assembly .Net objects. 提供对所有已知程序集.Net对象的搜索。

Since you are using c# I'm thinking maybe you are in a Windows Env. 由于您使用的是C#,所以我想也许您正在使用Windows Env。 Something I know little about :) 我不太了解的东西:)

If you are dealing with a unix env, you could just pipe your output thru SSH, which would also take care of encryption overhead. 如果您要处理的是unix env,则可以通过SSH传递输出,这也可以解决加密开销。

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

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