C# 远程服务器返回错误:(550) 文件不可用(制作 ftp 目录时出错)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17150998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The remote server returned an error: (550) File unavailable(Error occured on making ftp directory)
提问by user2493843
I am developing a wpf application and I want to make a directory on ftp using C# with different usernames and if it already exists then save files on existing directory.
我正在开发一个 wpf 应用程序,我想使用不同用户名的 C# 在 ftp 上创建一个目录,如果它已经存在,则将文件保存在现有目录中。
I've successfully created the logic of checking the existing directory but while creating a new directory I've got an exception on runtime:
我已经成功创建了检查现有目录的逻辑,但是在创建新目录时,我在运行时遇到了异常:
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
I've checked different solutions on the internet and most are saying that it is due to write permissions. I am assigning the ftp folder write permissions, but I am still having the problem. Please Help?
我在互联网上检查了不同的解决方案,大多数都说这是由于写权限。我正在分配 ftp 文件夹写入权限,但问题仍然存在。请帮忙?
Here is my code:
这是我的代码:
static void CreateFtpFolder(string source)
{
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(source);
request.Credentials = new NetworkCredential(ftpusername, ftppassword);
request.Method = WebRequestMethods.Ftp.MakeDirectory;
request.UsePassive = true;
request.UseBinary = false;
request.KeepAlive = false;
request.Proxy = null;
FtpWebResponse ftpResp = request.GetResponse() as FtpWebResponse;
}
I am having the error on FtpWebResponse.
我在FtpWebResponse.
采纳答案by Kashif R
Your code look fine.......you are saying that you have assigned permission too. The only problem is that you may be passing a wrong "Source"which is causing problem..Check your source string it may have an error......
你的代码看起来不错.......你是说你也分配了权限。唯一的问题是你可能传递了一个错误的“源”,这导致了问题......检查你的源字符串它可能有错误......
path should be like
路径应该像
WebRequest request = WebRequest.Create("ftp://host.com/directory123");
it mean directory will be created with name "directory12" if your are specifying path like this
这意味着如果您指定这样的路径,将创建名为“directory12”的目录
WebRequest request = WebRequest.Create("ftp://host.com/directory123/directory1234");
this mean "ftp://host.com/directory123/" should already exist and new directory will be created with name "directory1234" hope it will help
这意味着“ ftp://host.com/directory123/”应该已经存在并且将创建名为“directory1234”的新目录希望它会有所帮助
回答by Andrew - OpenGeoCode
You get that error if the directory already exists. Pretty non-descriptive error message (lol). Must put a try catch around the call to request.GetResponse()
如果目录已存在,则会出现该错误。相当非描述性的错误信息(笑)。必须在对 request.GetResponse() 的调用周围放置一个 try catch
try
{
FtpWebResponse ftpResp = request.GetResponse() as FtpWebResponse;
}
catch ( Exception ex ) { /* ignore */ }
回答by ykay
If the problem is a Windows Server-side permission issue and you have access to this FTP server, you may be able to resolve it by modifying the permission and adding 'Write' permission for the username that you are authenticating with on the actual physical directory.
如果问题是 Windows 服务器端权限问题并且您有权访问此 FTP 服务器,您可以通过修改权限并为您在实际物理目录上进行身份验证的用户名添加“写入”权限来解决此问题.
e.g. If 'ftp://host/' points to 'c:\inetpub\ftproot' on your server, then allow 'Write' permission for the user on that directory.
例如,如果“ ftp://host/”指向您服务器上的“c:\inetpub\ftproot”,则允许该用户在该目录上具有“写入”权限。
I was setting up my own IIS 7 FTP server and spent a good hour or two trying to get such a simple snippet of C# client code to work, so thought I'd contribute for those in similar situations.
我正在设置我自己的 IIS 7 FTP 服务器,并花了一两个小时试图让这样一个简单的 C# 客户端代码片段工作,所以我想我会为那些处于类似情况的人做出贡献。

