这是我试图上传到ftp服务器的路径:
_ftp://ftp-server/products/productxx/versionxx/releasexx/delivery/data.zip
问题是服务器上不存在文件夹"productxx/versionxx/releasexx/delivery/"。
我可以在上传.zip文件时自动创建c#文件吗?
我目前的编码是:
FtpWebRequest request =
(FtpWebRequest)WebRequest.Create(pathToFtp);
// Method set to UploadFile
request.Method = WebRequestMethods.Ftp.UploadFile;
// set password and username
request.Credentials = new NetworkCredential(UserName, Password);
// write MemoryStream in ftpStream
using (Stream ftpStream = request.GetRequestStream())
{
memoryStream.CopyTo(ftpStream);
}我得到了System.Net.WebException:“无法连接到FTP:(553)文件名不允许”在“ the (Stream ftpStream =request.GetRequestStream()”中)
但是如果我的_ftp://ftp-server/products/data.zip是pathToFtp的话,它还能正常工作。
发布于 2017-10-13 11:48:25
可用的请求方法之一是WebRequestMethods.Ftp.MakeDirectory。你应该能用它来做你想做的事。
像这样的东西(虽然我还没有测试),应该可以做到这一点:
async Task CreateDirectory(string path)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(path);
request.Method = WebRequestMethods.Ftp.MakeDirectory;
using (var response = (FtpWebResponse)(await request.GetResponseAsync()))
{
Console.WriteLine($"Created: {path}");
}
}这个问题在这里得到了更详细的回答,How do I create a directory on ftp server using C#?
https://stackoverflow.com/questions/46729113
复制相似问题