K
kh
Hi. I have an issue with file uploads using the FtpWebRequest class. When the
code is deployed at a client site transfer speed is very slow. I write the
local file stream to the request stream but with large files (i.e. long
upload times) my app hangs on the call to requestStream.Close():
// sourceStream is a FileStream to a local file
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(_uri);
....
Stream requestStream = request.GetRequestStream();
byte[] buffer = new byte[DEFAULT_BUFFER_LENGTH];
int bytesRead;
do
{
bytesRead = sourceStream.Read(buffer, 0, buffer.Length);
requestStream.Write(buffer, 0, bytesRead);
} while (bytesRead >= buffer.Length);
// code hangs here
requestStream.Close();
FtpWebResponse response = (FtpWebResponse) request.GetResponse();
response.Close();
The corresponding server log is as follows:
USER MyUsername - 331 0 0 0 0 FTP - - - -
PASS - - 230 0 0 0 0 FTP - - - -
CWD /Incoming - 250 0 0 0 0 FTP - - - -
created /Incoming/MyFile.xml.pgp - 226 0 0 53031735 457167 FTP - - - -
Note the 226 return code (i.e. success).
If the user uploads small files all works as expected. I know there can be
issues with idle command chanels timing out, but what can I do to correct
this, or at least recover from it? At the moment I cannot even throw an
exception.
Cheers
code is deployed at a client site transfer speed is very slow. I write the
local file stream to the request stream but with large files (i.e. long
upload times) my app hangs on the call to requestStream.Close():
// sourceStream is a FileStream to a local file
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(_uri);
....
Stream requestStream = request.GetRequestStream();
byte[] buffer = new byte[DEFAULT_BUFFER_LENGTH];
int bytesRead;
do
{
bytesRead = sourceStream.Read(buffer, 0, buffer.Length);
requestStream.Write(buffer, 0, bytesRead);
} while (bytesRead >= buffer.Length);
// code hangs here
requestStream.Close();
FtpWebResponse response = (FtpWebResponse) request.GetResponse();
response.Close();
The corresponding server log is as follows:
USER MyUsername - 331 0 0 0 0 FTP - - - -
PASS - - 230 0 0 0 0 FTP - - - -
CWD /Incoming - 250 0 0 0 0 FTP - - - -
created /Incoming/MyFile.xml.pgp - 226 0 0 53031735 457167 FTP - - - -
Note the 226 return code (i.e. success).
If the user uploads small files all works as expected. I know there can be
issues with idle command chanels timing out, but what can I do to correct
this, or at least recover from it? At the moment I cannot even throw an
exception.
Cheers