无法在FTP中创建目录 [英] Unable to Create Directory in FTP
问题描述
尝试在ftp中创建目录并上传文件时出现此错误
远程服务器返回错误:(550)文件不可用(例如,找不到文件,无法访问).
以下是我编写的代码
Hi,
I am getting this error when I am trying to create directory and upload file in ftp
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
The following is the code I have written
string fileName = System.IO.Path.GetFileName(filepath);
FileStream stream = File.OpenRead(fileName);
string fullurlpath = "<b>ftp://data.datafort.com.sg:2121/WVDataFiles/AMDemo/</b>" + fileName;
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(fullurlpath);
request.Method = WebRequestMethods.Ftp.MakeDirectory;
request.Method = WebRequestMethods.Ftp.UploadFile;
string strUserId = Convert.ToString(dtClient.Rows[0]["FtpUserID"]);
string strPassword = Convert.ToString(dtClient.Rows[0]["FtpPassword"]);
request.Credentials = new NetworkCredential(strUserId, strPassword);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();
Stream reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
WVDataFiles已经存在于ftp中,我正在尝试创建AMDemo文件夹并通过代码上传文件名(xml文件).但出现错误
远程服务器返回错误:(550)文件不可用(例如,找不到文件,无法访问).
但是,如果我手动创建该文件夹,则会创建该文件夹,但是会通过代码抛出错误.谁能帮我解决问题.
在此先感谢
Padma
WVDataFiles is already there in ftp, I am trying to create AMDemo folder and upload filename(xml file) through code. but I am getting error
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
but if I create the folder manually, it is being created but throwing error through code. Can anyone help me to solve the issue.
Thanks in Advance
Padma
推荐答案
request.Method = WebRequestMethods.Ftp.MakeDirectory;
request.Method = WebRequestMethods.Ftp.UploadFile;
在设置创建目录的请求后,立即将其更改为上载文件.这就是导致您出现问题的原因-删除UploadFile行.
Immediately after setting the request to make the directory, you go and change it to upload a file. That''s what''s causing your problem - remove the UploadFile line.
这篇关于无法在FTP中创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!