ResolveHost ();
OpenControlConnection ();
+ CWDAndSetFileName (requestUri);
+ SetType ();
switch (method) {
// Open data connection and receive data
case WebRequestMethods.Ftp.DownloadFile:
- CWDAndSetFileName (requestUri);
- SetType ();
- DownloadData ();
- break;
case WebRequestMethods.Ftp.ListDirectory:
case WebRequestMethods.Ftp.ListDirectoryDetails:
- SetType ();
DownloadData ();
break;
// Open data connection and send data
case WebRequestMethods.Ftp.AppendFile:
case WebRequestMethods.Ftp.UploadFile:
case WebRequestMethods.Ftp.UploadFileWithUniqueName:
- CWDAndSetFileName (requestUri);
- SetType ();
UploadData ();
break;
// Get info from control connection
if (method == WebRequestMethods.Ftp.Rename)
method = RenameFromCommand;
- status = SendCommand (method, requestUri.LocalPath);
+ status = SendCommand (method, file_name);
ftpResponse.Stream = new EmptyStream ();
throw CreateExceptionFromResponse (status);
break;
case WebRequestMethods.Ftp.DeleteFile:
- if (status.StatusCode != FtpStatusCode.FileActionOK)
+ if (status.StatusCode != FtpStatusCode.FileActionOK) {
throw CreateExceptionFromResponse (status);
+ }
break;
}
WebExceptionStatus.UnknownError, null);
string msg = status.StatusDescription.Substring (4);
- if (msg [0] == '"')
- msg = msg.Substring (1, msg.Length - 2);
+ if (msg [0] == '"') {
+ int next_quote = msg.IndexOf ('\"', 1);
+ if (next_quote == -1)
+ throw new WebException ("Error getting current directory: PWD -> " + status.StatusDescription, null,
+ WebExceptionStatus.UnknownError, null);
+
+ msg = msg.Substring (1, next_quote - 1);
+ }
if (!msg.EndsWith ("/"))
msg += "/";
}
IPEndPoint ep = (IPEndPoint) sock.LocalEndPoint;
- string ipString = ep.Address.ToString ().Replace (".", ",");
+ string ipString = ep.Address.ToString ().Replace ('.', ',');
int h1 = ep.Port >> 8; // ep.Port / 256
int h2 = ep.Port % 256;
Socket s = InitDataConnection ();
- if(method != WebRequestMethods.Ftp.UploadFileWithUniqueName) {
+ if (method != WebRequestMethods.Ftp.ListDirectory && method != WebRequestMethods.Ftp.ListDirectoryDetails &&
+ method != WebRequestMethods.Ftp.UploadFileWithUniqueName) {
status = SendCommand (method, file_name);
} else {
status = SendCommand (method);