使用msbuild FtpUploadDirectoryContent,目录名无效

时间:2013-10-08 12:26:44

标签: msbuild msbuildcommunitytasks

我正在使用msbuild脚本并收到以下错误消息

 The "FtpUploadDirectoryContent" task failed unexpectedly.
error MSB4018: System.IO.IOException: The directory name is invalid.

我的脚本是

<FtpUploadDirectoryContent
        ServerHost="$(ftpHost)"
        Port="21"
        Username="$(ftpUser)"
        Password="$(ftpPass)"
        LocalDirectory="E:\demo\test.txt"
        RemoteDirectory="website/config"
        Recursive="true"
        />

我的IIS托管路径是C:\ inetpub \ wwwroot和site \ config文件夹存在于[C:\ inetpub \ wwwroot \ website \ config]中。但是我仍然收到消息,如目录名无效< /strong>.please让我知道如何解决这个问题。如果需要任何其他的东西,这个...的正确systax是什么建议

1 个答案:

答案 0 :(得分:0)

<强> LocalDirectory = “E:\演示\ 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。