无法打开上传到FTP的文件

问题描述 投票:0回答:0

我试图在我的ftp服务器上上传一个excel文件。 我可以上传,但无法打开上传的文件。我也尝试了上传照片。 同样的问题。 ftp上的文件似乎为“ 0字节”。

这是我的代码;

OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.ShowDialog();
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://labquiz.hostoi.com/public_html/dosyalar/" + openFileDialog.SafeFileName);
        request.Method = WebRequestMethods.Ftp.UploadFile;
        request.Credentials = new NetworkCredential("a3026029", "*******");
        request.UsePassive = true;
        request.UseBinary = true;
        request.KeepAlive = true;
        FileStream stream = File.OpenRead(openFileDialog.InitialDirectory + openFileDialog.FileName);
        byte[] buffer = new byte[stream.Length];
        stream.Read(buffer, 0, buffer.Length);
        stream.Close();
        FtpWebResponse response = (FtpWebResponse)request.GetResponse();
        MessageBox.Show("Upload File Complete, Status: " + response.StatusDescription);
        response.Close();
c# ftp
© www.soinside.com 2019 - 2024. All rights reserved.