FTP伺服器移動檔案目錄

來源:互聯網
上載者:User

標籤:

已經可以移動檔案了,原因是路徑問題。還是用的Rename方法。原因是RenameTo=“”;這裡的路徑之前沒包含檔案名稱,而且相對路徑和絕對路徑都沒弄對,所以之前一直不相信別人說的Rename可以移動檔案。現在結貼了,謝謝大家!為了讓後來人能夠找到答案,我把代碼貼出來,做個示範:
ftp:10.62.80.x/TEMP/aa.pdf   要移動的檔案路徑(源檔案路徑)
ftp:10.62.80.x/Youku/aa.pdf   要移動目錄(移動後的檔案路徑)
執行個體:
  FtpWebRequest reqFTP;
            try
            {
               
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://10.62.80.x/TEMP/aa.pdf")); //x代表實際Ip,這裡用未知數代替
                reqFTP.Method = WebRequestMethods.Ftp.Rename;
                reqFTP.KeepAlive = false;
                reqFTP.RenameTo = "~/Youku/aa.pdf";  //這裡用的是絕對路徑,大家可以根據實際情況修改
                reqFTP.UseBinary = true;
                reqFTP.Credentials = new NetworkCredential(loginName, PassWord);
                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                Stream ftpStream = response.GetResponseStream();
                
                ftpStream.Close();
                response.Close();
            }
            catch (Exception ex)
            {
               
            }

上面是我在csdn的求助貼

FTP伺服器移動檔案目錄

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.