FtpWebRequest and (550) File unavailable (e.g., file not found, no access)

25 January 2010 14:44

Let’s just give you the punchline of the post first:

If you’re trying to access the file “ftp://somehost/somedirectory/some.filename” and you’re getting a 550 error, you need to change the Uri to “ftp://somehost/%2f/somedirectory/some.filename”

You can find more details on Mariya Atanasova's Blog.  OK, now that I’ve performed the public service, let’s explain why this works. 

FtpWebRequest interprets every directory in the chain as a “CWD” command (CD in DOS terminology).  Each of these is relative to the previous location.  The first location is wherever the FTP server dumped you on logon.  A behaviour that is irritating in interactive mode is made just plain unusable as an API.  What’s worse, Microsoft have actually implemented the spec correctly (section 3.2.2 if you really care).  This basically means that FTP urls don’t work the way you expect and don’t behave in a similar way to HTTP urls.

So, to fix this, we need to first change to the root directory.  That, of course, means executing a “CWD /” command.  Of course, since / is a special character in the URL syntax, you end up having to write “%2F” to trick the FtpWebRequest into doing the right thing.  Ultimately, the moral of this story is that FtpWebRequest and ftp URIs are the wrong model for interacting with FTP.  I can’t see that being changed anytime soon, however.

Comments
Gravatar
# re: FtpWebRequest and (550) File unavailable (e.g., file not found, no access)
Posted by Carol on 21/11/2011 04:01
Do we need to change our URI... or... execute CMD /????

You say 1... but then you do the other.
Gravatar
# re: FtpWebRequest and (550) File unavailable (e.g., file not found, no access)
Posted by Julian on 21/11/2011 11:44
Changing the URI causes CWD / to be called. I hope that's more clear.
Gravatar
# re: FtpWebRequest and (550) File unavailable (e.g., file not found, no access)
Posted by doen't matter on 03/12/2011 13:52
oh my god i love you. seriously, you probably saved lives, if i had to spend any more time with my ftp file list function i would have gone "hulk" on the entire city.
Something to add?

Talking sense? Talking rubbish? Something I'm missing? Let me know!

Fields denoted with a "*" are required.

 (will not be displayed)

 
Please add 2 and 7 and type the answer here:

Preview Your Comment