我正在努力将文件上传和下载到UWP / Windows应用商店应用中的FTP服务器。 FtpWebRequest Class丢失,因此您必须使用自己的Ftp客户端。我还没有找到任何有用的开源库。我试过Windows 8.1 Sockets: Ftp Client Sample with Sockets in C#/Xaml;目录列表工作正常,但上传/下载在几个字节后中断。可能是缓冲问题?这是上传流,下载功能在msdn网站上。
using (var stream = await ftpClient.OpenWriteAsync(newFilePath))
{
var bytes = System.Text.Encoding.UTF8.GetBytes(filecontent);
await stream.WriteAsync(bytes.AsBuffer());
await stream.FlushAsync();
}
或
using (var stream = await OpenWriteAsync(destination))
{
// A more efficient way, maybe a DataReader can be used here
using (var readStream = await file.OpenReadAsync())
{
var buffer = new byte[512].AsBuffer();
var resultingBuffer = new byte[0];
while (true)
{
IBuffer readBuffer = await readStream.ReadAsync(buffer, 512, InputStreamOptions.Partial);
if (readBuffer.Length == 0) break;
resultingBuffer = resultingBuffer.Concat(readBuffer.ToArray()).ToArray();
}
await stream.WriteAsync(resultingBuffer.AsBuffer());
await stream.FlushAsync();
}
}
我读到BackgroundTransfer
类不支持FTP上传。有人找到了将文件加载到UWP应用程序中受密码保护的FTP服务器的解决方案吗?
谢谢你的帮助!