P
Pure Deal
Guest
I have the below code to upload a file to FTP which has security enabled along with PROT P
FtpWebRequest fwr = (FtpWebRequest)FtpWebRequest.Create("ftp://mysite" + nameOfFile);
fwr.Credentials = new System.Net.NetworkCredential(username, password);
fwr.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
fwr.UseBinary = true;
fwr.KeepAlive = true;
fwr.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = (s, certificate, chain, sslPolicyErrors) => true;
System.IO.FileInfo fi = new System.IO.FileInfo(filePath);
fwr.ContentLength = fi.Length;
byte[] buffer = new byte[4097];
int bytes = 0;
int total_bytes = (int)fi.Length;
try
{
System.IO.FileStream fs = fi.OpenRead();
System.IO.Stream rs = fwr.GetRequestStream();
while (total_bytes > 0)
{
bytes = fs.Read(buffer, 0, buffer.Length);
rs.Write(buffer, 0, bytes);
total_bytes = total_bytes - bytes;
}
fs.Close();
rs.Close();
FtpWebResponse uploadResponse = (FtpWebResponse)fwr.GetResponse();
var value = uploadResponse.StatusDescription;
uploadResponse.Close();
I use ftp:// as using any other protocol i.e. ftpes throws an error.
For some reason if PROT P is disabled on the receiving end the file is transferred successfully otherwise its not. No error messages are thrown.
Is there something im missing?
Continue reading...
FtpWebRequest fwr = (FtpWebRequest)FtpWebRequest.Create("ftp://mysite" + nameOfFile);
fwr.Credentials = new System.Net.NetworkCredential(username, password);
fwr.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
fwr.UseBinary = true;
fwr.KeepAlive = true;
fwr.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = (s, certificate, chain, sslPolicyErrors) => true;
System.IO.FileInfo fi = new System.IO.FileInfo(filePath);
fwr.ContentLength = fi.Length;
byte[] buffer = new byte[4097];
int bytes = 0;
int total_bytes = (int)fi.Length;
try
{
System.IO.FileStream fs = fi.OpenRead();
System.IO.Stream rs = fwr.GetRequestStream();
while (total_bytes > 0)
{
bytes = fs.Read(buffer, 0, buffer.Length);
rs.Write(buffer, 0, bytes);
total_bytes = total_bytes - bytes;
}
fs.Close();
rs.Close();
FtpWebResponse uploadResponse = (FtpWebResponse)fwr.GetResponse();
var value = uploadResponse.StatusDescription;
uploadResponse.Close();
I use ftp:// as using any other protocol i.e. ftpes throws an error.
For some reason if PROT P is disabled on the receiving end the file is transferred successfully otherwise its not. No error messages are thrown.
Is there something im missing?
Continue reading...