2016-01-22 198 views
0

我無法找到我的文件已上傳到我的網站目錄中的位置......我知道它已上傳,因爲我的調試機器(帶有窗體的控制檯)是我的第一篇文章,所以對不起,如果我有點不好意思。我將在稍後將它變成一項任務,只是想確保它的工作。謝謝!C#Ftp服務器上傳Go-Daddy

try 
     { 
      FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create("ftp:website"); 
      ftp.Method = WebRequestMethods.Ftp.UploadFile; 
      Console.WriteLine("Created Web Request"); 

      ftp.Credentials = new NetworkCredential("something", "something"); 
      Console.WriteLine("Entered Credentials"); 

      StreamWriter write = new StreamWriter("reviewSUP.txt"); 
      write.WriteAsync(trkBarShieldsUp.Value.ToString()); 
      Console.WriteLine("Wrote File: reviewSUP.txt"); 
      write.Close(); 
      Console.WriteLine("Closed Stream"); 

      StreamReader read = new StreamReader("reviewSUP.txt"); 
      byte[] filecontents = Encoding.UTF8.GetBytes(read.ReadToEnd()); 
      read.Close(); 
      Console.WriteLine("Closed Stream"); 
      ftp.ContentLength = filecontents.Length; 
      Console.WriteLine("Read File And Its Properties"); 

      Stream reqstrm = ftp.GetRequestStream(); 
      reqstrm.Write(filecontents, 0, filecontents.Length); 
      reqstrm.Close(); 
      Console.WriteLine("Finishing Touches, Request Stream Done"); 

      FtpWebResponse response = (FtpWebResponse)ftp.GetResponse(); 
      Console.WriteLine("Getting Response. . ."); 

      Console.WriteLine("Completed Upload, Status {0}", response.StatusDescription); 

      response.Close(); 

      Console.WriteLine("Response CLOSED"); 
     } 

     catch(Exception ex) 
     { 
      MessageBox.Show(ex.ToString()); 
      Console.WriteLine("Error: {0}", ex.ToString()); 
     } 
+0

通常你的文件將節省到你的'FtpWebRequest'。在這種情況下進入'ftp:website'路徑。 –

回答

0

我relised好想忘了把.TXT上的目錄結束shoudl是ftp:website/filename.txt