我正在构建一个解决方案,其中WCF服务充当FTP服务器之间的网关,它必须通过FTP协议(Linux服务器)和Windows客户端应用程序远程访问.服务本身将托管在Windows IIS服务器上.
我的模型基于一篇关于使用WCF通过http传输文件的文章,但问题是:
我必须先等待文件在Windows服务器上下载,然后再将其放到客户端,这可能是一个主要的性能问题.我想直接将文件从FTP服务器传输到客户端,而不必先下载它.
这是代码..
public class TransferService : ITransferService{
Starksoft.Net.Ftp.FtpClient ftp = new Starksoft.Net.Ftp.FtpClient();
public RemoteFileInfo DownloadFile(DownloadRequest request)
{
RemoteFileInfo result = new RemoteFileInfo();
try
{
string filePath = System.IO.Path.Combine(@"C:\UploadFiles\ServerDownloadFiles", request.FileName);
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
ftp = new Starksoft.Net.Ftp.FtpClient("127.0.0.1"); //remote ftp address
ftp.Open("user", "pass");
// here is waiting for the file to get downloaded from ftp server
System.IO.FileStream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
ftp.GetFileAsync(request.FileName, stream, true);
stream.Close();
stream.Dispose();
// this will read and be streamed to client …Run Code Online (Sandbox Code Playgroud)