LocalDirectory ="E:\demo\test.txt"
你给了它一个文件名,而不是一个目录。
E:\demo\test.txt 是一个文件名。
这是来自的代码
https://github.com/loresoft/msbuildtasks/blob/master/Source/MSBuild.Community.Tasks/Ftp/FtpUploadDirectoryContent.cs
try
{
UploadDirectory( LocalDirectory, "*.*", Recursive );
}
catch(FtpException caught)
{
Log.LogErrorFromException( caught, false );
Log.LogError( "Couldn't upload directory." );
return false;
}
foreach(string file in Directory.GetFiles( localPath, mask ))
{
String filename = Path.GetFileName( file );
Store( file, filename );
Log.LogMessage( MessageImportance.Low, "{0} uploaded succesfully.", localPath );
}
所以你想要做的基本上是:
Directory.GetFiles( "E:\demo\test.txt" , "*.* ))
这是行不通的。
将其更改为:
LocalDirectory="E:\demo\"
来自上面 github 链接的示例代码。
/// <Target Name="DeployWebsite">
/// <FtpUploadDirectoryContent
/// ServerHost="ftp.myserver.com"
/// Port="42"
/// Username="user"
/// Password="p@ssw0rd"
/// LocalDirectory="c:\build\mywebsite"
/// RemoteDirectory="root\www\mywebsite"
/// Recursive="true"
/// />
注意:LocalDirectory 不引用文件名。
如果要上传单个文件,可以使用以下替代方法:
https://www.assembla.com/spaces/GHFtpTask/wiki/Home/history
MSBuild 的 FtpTask 的主要特点是:
**Upload, download or delete a single file on a FTP server**
Recursively upload, download or delete a directory
Use multiple FTP connections simultaneously
MSBuild 的 FtpTask 需要 .NET 2.0。