I have the following code to upload a file with C#. but i can not. i got " Error : Invalid URI: The format of the URI could not be determined"
private
void FTPMessage(string supplierKey, Stream stream)
{
StreamReader sourceStream = null;
Stream requestStream = null;
try
{
// Get the object over an ftp server URI used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(test.Resoures.ftp_web_request);
// Set the FTP method to execute.
request.Method =
WebRequestMethods.Ftp.UploadFile;
// Set the network credentials.
request.Credentials =
new NetworkCredential(
test.Properties.Resorces
_CREDENTIALS_USERNAME,
test.Properties.Resorces
_CREDENTIALS_PASSWORD);
// Copy the contents of the file to the request stream.
sourceStream =
new StreamReader(stream);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
request.RenameTo = supplierKey +
DateTime.Now.ToString("yyyyMMddHHmmss") + "0.xml";
requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
}
catch (Exception ex)
{
preComLog.Write(
" FTPMessage() - Error : " + ex.Message);
}
finally
{
if (sourceStream != null)
sourceStream.Close();
if (requestStream != null)
requestStream.Close();
}
}