0
Srs(as), good afternoon,
I am creating a service that will upload some files to an FTP link, however this is like HTTPS (https://path/path).
occurs that the class Ftpwebrequest does not allow the use of Uri hhtp/https, the error occurs below.
Could help?
Unable to cast Object of type 'System.Net.Httpwebrequest' to type 'System.Net.Ftpwebrequest'.
below send the code snippet I am 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://camio.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
Great - using HTTP (not FTP) worked!
– carlosfigueira