简体   繁体   中英

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.

Do i generate them to disk then upload them to the FTP server? or is there a way to open a stream to an FTP server and write the files directly?

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. The for loop in the method is just to demonstrate writing to the FTP stream. 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?

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

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:

View > other windows > object browser

Is supplies a search over all known assembly .Net objects.

Since you are using c# I'm thinking maybe you are in a 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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