Sirs, good afternoon,
I'm creating a service that will upload some files to an FTP link, but this is like HTTPS ( link ).
It occurs that the FtpWebRequest class does not allow the use of uri hhtp / https, with the error below occurring.
Could you help?
Unable to cast object of type 'System.Net.HttpWebRequest' to type 'System.Net.FtpWebRequest'.
below, I'm sending the code snippet I'm using.
string uriPath = "https//caminho/path";
FtpWebRequest request;
FtpWebResponse response;
try
{
request = (FtpWebRequest)WebRequest.Create(uriPath);//Aqui ocorre o erro!!!!
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(userCred, passCred);
request.UsePassive = true;
DirectoryInfo dir = new DirectoryInfo(caminhoPath);
foreach (FileInfo file in dir.GetFiles())
{
FileInfo arquivo = new FileInfo(file.FullName);
byte[] fileContents = new byte[arquivo.Length];
using (FileStream fr = arquivo.OpenRead())
{
fr.Read(fileContents, 0, Convert.ToInt32(arquivo.Length));
}
using (Stream writer = request.GetRequestStream())
{
writer.Write(fileContents, 0, fileContents.Length);
}
response = (FtpWebResponse)request.GetResponse();
}
}
catch (WebException webEx)
Using the address as " ftp://path.com:443/path "
Returns the error in the GetRequestStream () call.
using (Stream writer = request.GetRequestStream())//Erro aqui!!!
{
writer.Write(fileContents, 0, fileContents.Length);
}
response = (FtpWebResponse)request.GetResponse();
The requested URI is invalid for this FTP command