Click here to Skip to main content
15,916,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Net;
namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        public static string fileName;
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            {  // Create OpenFileDialog 
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();



                // Set filter for file extension and default file extension 
                dlg.DefaultExt = ".*";



                // Display OpenFileDialog by calling ShowDialog method 
                Nullable<bool> result = dlg.ShowDialog();


                // Get the selected file name and display in a TextBox 
                if (result == true)
                {
                    // Open document 

                    fileName = (dlg.FileName);


                }


                // Get the object used to communicate with the server.
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://94.73.145.160/Feba_Toplantı");
                request.Method = WebRequestMethods.Ftp.UploadFile;

                // This example assumes the FTP site uses anonymous logon.
                request.Credentials = new NetworkCredential("u6341930", "TPmp45D2");

                // Copy the contents of the file to the request stream.
                StreamReader sourceStream = new StreamReader(fileName.ToString());
                byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                sourceStream.Close();
                request.ContentLength = fileContents.Length;

                Stream requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();

                FtpWebResponse response = (FtpWebResponse)request.GetResponse();

                Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

                response.Close();


            }
        }
    }
}


What I have tried:

I am using C# WPF I try to upload file from ftp but I got error from this
StreamReader sourceStream = new StreamReader(fileName.ToString());
error is 550 no find file how can I fix my problem please help guys
Posted
Updated 26-Sep-17 21:44pm
v2

1 solution

 
Share this answer
 
Comments
ANIL AYDINALP 27-Sep-17 4:19am    
I don't understand about your file for example it make mor difficult for me or complicate
Graeme_Grant 27-Sep-17 4:51am    
The Library does all the work for you. Take your time and look at the sample code and projects. When you are reeady to use, you add the library using Nuget.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900