0
FTP 업로드시 테스트 할 때 위의 오류가 나타납니다. 하지만 내 로컬 컴퓨터에서이 코드를 실행하려고하면 오류가 발생합니다. 친절하게 조언하십시오. 아래'System.Net.FileWebRequest'형식의 개체를 'System.Net.HttpWebRequest'형식으로 캐스팅 할 수 없습니다.
다음내 코드 :
static void Main(string[] args)
{
var yourListOfFilePaths = Directory.GetFiles(filepath);
using (ZipFile zip = new ZipFile())
{
foreach (string filePath in yourListOfFilePaths)
{
zip.AddFile(filePath); // FILE PATH LOCATION/WHICH FOLDER FILES YOU WANTED TO ZIP
zip.Password = "abc1234"; // CHANGE YOUR PASSWORD HERE
}
zip.Save(ZipPath + "\\Batch_" + DateTime.Now.ToString("ddMMyy") + ".zip");
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("http://www.bitrix24.com/" + "\\Batch_" + DateTime.Now.ToString("ddMMyy") + ".zip");
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("[email protected]", "abc123");
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(ZipPath + "\\Batch_" + DateTime.Now.ToString("ddMMyy") + ".zip");
byte[] fileContents = File.ReadAllBytes("filepath");
sourceStream.Close();
request.ContentLength = fileContents.Length;
request.KeepAlive = false;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();
}
}
내가 수정하고 실행 때이 오류가 발생했습니다를 HTTP 프록시를 사용할 때 –
@JaydenNg 'request.Proxy = null'설정을 시도하십시오. –
이 요청입니다. 스트림 전에 넣으십시오. –