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

Monday, January 25, 2010 2:44 PM

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 11/21/2011 4:01 AM
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 11/21/2011 11:44 AM
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 12/3/2011 1:52 PM
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.
Gravatar
# re: FtpWebRequest and (550) File unavailable (e.g., file not found, no access)
Posted by Kishor on 5/4/2012 2:45 PM
Love you man...superb...It worked like magin .what the hell is this.
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 4 and 5 and type the answer here:

Preview Your Comment