I'm trying to stress-test my .NET application's function that uploads files via FTP(s) protocol. This function uses the .NET's built-in FtpWebResponse
class (in case a user's server does not support SSH connection.) I'm using the following code to try to create the "test up1/archive: * OR | or $ or < and >."
directory on an Ubuntu server in my user's directory:
//First call succeeds
string strPath = "ftp://webhost.com/%2F/UserDir/" +
Uri.EscapeDataString("test up1") + "/";
createDirViaFTP(strPath);
//but then this call fails
strPath += Uri.EscapeDataString("archive: * OR | or $ or < and >.") + "/";
createDirViaFTP(strPath);
static bool createDirViaFTP(string strURI)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(strURI);
request.EnableSsl = bUseSsl; //can be either false or true
request.Credentials = = new NetworkCredential(strUsrName, secUsrPwd);
request.UseBinary = true;
request.Timeout = -1;
request.Method = WebRequestMethods.Ftp.MakeDirectory;
try
{
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
{
if (response.StatusCode == FtpStatusCode.PathnameCreated)
{
//Created OK
return true;
}
}
}
catch(Exception ex)
{
//Failed
Console.WriteLine("EXCEPTION: Path=" + strURI + "\n" + ex.Message);
}
return false;
}
The second call to my createDirViaFTP
throws the following exception when I try to create "archive: * OR | or $ or < and >."
dir:
EXCEPTION: Path=ftp://webhost.com/%2F/UserDir/test%20up1/archive%3A%20*%20OR%20%7C%20or%20%24%20or%20%3C%20and%20%3E./
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
But why? What am I doing wrong here? All those symbols in the second directory name should be legal Linux file names. I can create that same directory via SSH shell.