使用C#在FTP上创建目录 [英] Make Directory on FTP using C#
问题描述
大家好,
我正在编写一段代码,使用c#在ftp上创建目录,一切似乎都很好,但我在运行时遇到异常远程服务器返回错误:(550)文件不可用(例如,找不到文件,没有访问权限)。我被卡住了,我不知道该怎么办。请调查并帮助我?
我正在使用的代码在这里:
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Net;
命名空间 makedirectory
{
class 计划
{
静态 void Main( string [] args)
{
FtpWebRequest request =(FtpWebRequest)FtpWebRequest.Create( ftp://127.0.0.1/ + NewDirectory);
request.Credentials = new NetworkCredential( 匿名, anonymous);
request.UsePassive = true ;
request.UseBinary = true ;
request.KeepAlive = false ;
Console.WriteLine( 获取响应);
request.Method = WebRequestMethods.Ftp.MakeDirectory;
使用( var resp =(FtpWebResponse)request.GetResponse())
{
Console.WriteLine(resp.StatusCode);
}
}
}
}
< blockquote> http: //www.aspxtutorial.com/post/2010/11/05/How-to-create-a-directory-on-FTP-Server-using-CsharpVBNET.aspx [ ^ ]
此外,
http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/86b6715d-be85-4765 -8a98-1e57d137289f [ ^ ]
使用系统;
使用 System.Net;
class 测试
{
静态 void Main()
{
WebRequest request = WebRequest.Create( ftp://host.com/directory跨度>);
request.Method = WebRequestMethods.Ftp.MakeDirectory;
request.Credentials = new NetworkCredential( user, pass);
使用( var resp =(FtpWebResponse)request.GetResponse())
{
Console.WriteLine(resp.StatusCode);
}
}
}
可能您没有对您尝试访问和创建的目录的写入权限里面有一个新目录。
Hi All,
I am writing a piece of code to make directory on ftp using c# and everything seems fine but i've got an exception on runtime that "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)." and i am stuck i don't know what to do. Please look into it and help me?
The code i am using goes here:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
namespace makedirectory
{
class Program
{
static void Main(string[] args)
{
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://127.0.0.1/" + "NewDirectory");
request.Credentials = new NetworkCredential("anonymous", "anonymous");
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
Console.WriteLine("Getting the response");
request.Method = WebRequestMethods.Ftp.MakeDirectory;
using (var resp = (FtpWebResponse)request.GetResponse())
{
Console.WriteLine(resp.StatusCode);
}
}
}
}
http://www.aspxtutorial.com/post/2010/11/05/How-to-create-a-directory-on-FTP-Server-using-CsharpVBNET.aspx[^]
Also,
http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/86b6715d-be85-4765-8a98-1e57d137289f[^]
using System; using System.Net; class Test { static void Main() { WebRequest request = WebRequest.Create("ftp://host.com/directory"); request.Method = WebRequestMethods.Ftp.MakeDirectory; request.Credentials = new NetworkCredential("user", "pass"); using (var resp = (FtpWebResponse) request.GetResponse()) { Console.WriteLine(resp.StatusCode); } } }
probably you do not have write permission to the directory you are trying to access and create a new directory inside that.
这篇关于使用C#在FTP上创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!