I have created a small windows forms application to upload the file to one of our client\'s ftp site. But the problem that I\'m having is that when I run this application on
I had this problem. Filezilla was fine, .net wasn't. It was to a wordpress server. To get it working, I changed the my code from this:
ftp://XXX.XXX.XXX.XXX//folder//" + txtFile.Text
to:
ftp://[FTPNAME]@XXX.XXX.XXX.XXX//" + txtFile.Text
and it now thankfully works.
I don't know if this is specific to Wordpress FTP folders.
It could be more simple.
I facing similar issue and i tried all the suggested solution but no one work. I'm figure out in simple manner like this one : take a look
Wrong code at my end
Dim request As Net.FtpWebRequest = CType(FtpWebRequest.Create("ftp://xxx.xxx.xxx.xxx/files"), FtpWebRequest)
Change it in this simple one :
Dim request As Net.FtpWebRequest = CType(FtpWebRequest.Create("ftp://xxx.xxx.xxx.xxx/files/youfilename.ext"), FtpWebRequest)
then procced with fill request and send to server :)
That's all.
Make sure that all permission on server work fine and u're using right credential.
Make sure target folder "outbox" exists. That was my problem with error 550.
Simply create target directory "output" before upload.
try
{
WebRequest request = WebRequest.Create("ftp://" + ftpServerIP + "/outbox");
request.Credentials = new NetworkCredential("user", "password");
request.Method = WebRequestMethods.Ftp.MakeDirectory;
using (var resp = (FtpWebResponse)request.GetResponse())
{
Console.WriteLine(resp.StatusCode);
}
}
catch (WebException ex)
{
FtpWebResponse response = (FtpWebResponse)ex.Response;
if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
{
response.Close();
//already exists
}
else
{
response.Close();
//doesn't exists = it's another exception
}
}
In order to resolve this issue, it is required to force the System.Net.FtpWebRequest command to revert back to the old behavior of how it used to work in .Net Framework 2.0/3.5 and issue the extra CWD command before issuing the actual command.
In order to do this, the following code needs to be placed before any instance of the System.Net.FtpWebRequest class is invoked. The code below only needs to be called once, since it changes the settings of the entire application domain.
private static void SetMethodRequiresCWD()
{
Type requestType = typeof(FtpWebRequest);
FieldInfo methodInfoField = requestType.GetField("m_MethodInfo", BindingFlags.NonPublic | BindingFlags.Instance);
Type methodInfoType = methodInfoField.FieldType;
FieldInfo knownMethodsField = methodInfoType.GetField("KnownMethodInfo", BindingFlags.Static | BindingFlags.NonPublic);
Array knownMethodsArray = (Array)knownMethodsField.GetValue(null);
FieldInfo flagsField = methodInfoType.GetField("Flags", BindingFlags.NonPublic | BindingFlags.Instance);
int MustChangeWorkingDirectoryToPath = 0x100;
foreach (object knownMethod in knownMethodsArray)
{
int flags = (int)flagsField.GetValue(knownMethod);
flags |= MustChangeWorkingDirectoryToPath;
flagsField.SetValue(knownMethod, flags);
}
}
http://support.microsoft.com/kb/2134299
The server usually returns a relevant error message with the 550
code. But the FTP implementation in .NET framework translates all FTP status codes to its own (localized) message. Particularly code 550 is translated to "File unavailable". That, in many cases, hides away the real problem.
Enable .NET logging to see the real error message from the server:
Output log using FtpWebRequest
Here are some various common scenarios that lead to 550 error:
I was having the same problem, when i compared with the ftpuri and User Name Path it is resolved When I create ftp access i have chose the path as /directory name
in the ftpuri when i included the directory name it gave the error and when i removed the directory name it is resolved.
ftpuri with error
"ftp://www.example.com/Project/yourfilename.ds"
ftpuri resolved
"ftp://www.example.com/yourfilename.ds"
ftp access folder "/Project"